如何将一个文本区里的内容中的空格,回车,换行字符去掉并统计出字数?
关于字数是这样规定的,中文字为二个字节,英文或标点符号为一个字节,统计出这个文本区里的所有去掉空格、回车、换行的内容的字节数。请问高手用什么方法或函数可以实现,统计又如何实现呢?决定散100分。急!!!
---------------------------------------------------------------
for(int i=0, sum=0;i
1<str.length;i++) '求字符串的绝对字节数(汉字为两个字节)="" )="" \---------------------------------------------------------------="" continue;="" count="0" count,i="" dim="" function="" if="" if(str[i]=" " my_len(str)="" str<="" sum++;="" {="" }="" 用下面这个函数="">"" then
2for i=1 to len(str)
3if asc(mid(str,i,1))<0 then
4count=count+2
5else
6count=count+1
7end if
8next
9end if
10my_len=count
11end function
12
13这个函数可应用在服务器端也可用在客户端,调用的时候这样
14
15总字数=my_len(str)
16里面的str就是你取到的文本框里面的内容,不用替换
17\---------------------------------------------------------------
18
19<textarea name="a" style="width:50%;height:50%"></textarea><input onclick="geth(a)" type="button" value="get"/>
20<script>
21function geth(o)
22{
23str=o.value.replace(/\s/g,'')
24alert(str)
25var tmp = 0;
26for(var i=0;i<str.length;i++)
27{
28if(str.charCodeAt(i)>255)
29tmp += 2
30else
31tmp += 1
32}
33alert(tmp)
34}
35
36</script>
37
38
39\---------------------------------------------------------------
40
41
42
43function getStrLeng(byval str,byref length)
44str = replace(str,chr(13)&chr(10),"")
45length = len(str)
46getStrLeng = str
47end function
48
49用法
50dim str,newStr,strLen
51newStr=getStrLeng(str,strLen)
52
53newStr就是替换后的str,strLen就是length
54\---------------------------------------------------------------
55
56<form name="form1">
57<textarea name="txt"></textarea>
58<input onclick="mm()" type="button" value="ok"/>
59</form>
60<script language="javascript">
61function String.prototype.lenB(){return this.replace(/[^\x00-\xff]/g,"**").length;}
62function mm()
63{
64var s = document.form1.txt.value;
65s = s.replace(/\r\n/g, "").replace(/ /g, "");
66alert(s.lenB());
67}
68</script>
69\---------------------------------------------------------------
70
71写错了,更正
72function getStrLeng(byval str,byref length)
73str = clearString(str)
74do while instr(1,str,chr(13)&chr(10))>0
75str = clearString(str)
76loop
77length = len(str)
78getStrLeng = str
79end function
80
81function clearString(str)
82clearString = replace(str,chr(13)&chr(10),"")
83
84end function
85
86
87用法
88dim str,newStr,strLen
89newStr=getStrLeng(str,strLen)
90
91newStr就是替换后的str,strLen就是length
92\---------------------------------------------------------------
93
94<textarea name="txt"></textarea>
95<input onclick="count()" type="button" value="ok"/>
96<script language="javascript">
97function String.prototype.lenB(){return this.replace(/[^\x00-\xff]/g,"**").length;}
98function count()
99{
100var s =txt.value;
101s = s.replace(/(\r\n ¦\s)/g, "")
102alert(s.lenB());
103}
104</script>
105\---------------------------------------------------------------
106
107<form name="form1">
108<textarea name="txt"></textarea>
109<input onclick='alert(document.form1.txt.value.replace(/\r\n/g, "").replace(/ /g, "").replace(/[^\x00-\xff]/g,"**").length)' type="button" value="ok"/>
110</form>
111\---------------------------------------------------------------
112
113<form onsubmit="return check()">
114
115在check()中写form1.input1.value=document.form1.txt.value.replace(/\r\n/g, "").replace(/ /g, "").replace(/[^\x00-\xff]/g,"**").length)'</form></str.length;i++)>