byte[] buffer = new byte[2];
FileStream fs = new FileStream(@"c:/1.txt", FileMode.Open, FileAccess.Read);
fs.Seek(-2, SeekOrigin.End);
fs.Read(buffer, 0, 2);
if ((char)buffer[0] == '/r' && (char)buffer[1] == '/n') {
Console.WriteLine("最后一个字符是回车符");
}
fs.Close();
JQuery 插件,光标处写入内容
/**
** 使用方法
*$(selector).insertAtCaret("value");
***/
$.fn.extend({
insertAtCaret: function (myValue) {
var $t = $(this)[0];
if (document.selection) {
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus();
}
else
if ($t.selectionStart || $t.selectionStart == '0') {
var startPos = $t.selectionStart;
var endPos = $t.selectionEnd;
var scrollTop = $t.scrollTop;
$t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
this.focus();
$t.selectionStart = startPos + myValue.length;
$t.selectionEnd = startPos + myValue.length;
$t.scrollTop = scrollTop;
}
else {
this.value += myValue;
this.focus();
}
}
})
//js保留两位小数
function fomatFloat(src, pos) {
return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
}
/*
*获取Url参数
*var classid = request("classid");
*var id = request("id");
*/
function request(paras) {
var url = location.href;
var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
var paraObj = {}
for (i = 0; j = paraString[i]; i++) {
paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if (typeof (returnValue) == "undefined") {
return "";
} else {
return returnValue;
}
}
/**
*去除字符串的收尾空格
*/
function trim(str) {
return str.replace(/(^/s*)|(/s*$)/g, "");
}