十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
x="a[11dsfsf]b"
创新互联公司主要从事成都网站设计、成都网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务上街,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
b=x.lastindexof("]")
a=x.indexof("[")
x=x.substring(0,a) "0" x.substring(b)
字符编码转换吗?
1.字符与gb2312(gbk的子集):
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
'这里可以类推出好几种。
将dll以文件方式以UTF-8的方式读入,然后接下来就替换字符串就可以了嘛
C#:
using System.IO;
...
string text;
text=File.ReadAllText(FilePath, Encoding.UTF8);
text.Replace("...","...");
...
-------------------------
还要谢谢你,不然我还不知道是UTF-8的编码格式,我有一个验证的问题可以解决了。
语法错误,没有存储函数的返回值。
temp.Replace("111", "22")
这个函数方法返回修改后的结果,并不修改参数变量本身,也就是按值传递,而不是按地址传递,正确用法:
temp=temp.Replace("111", "22")