ASP NET中有什么函数可以实现改变字符串中指定位置的字符串,其余不变?

2025-03-03 18:16:24
推荐回答(2个)
回答1:

用mid函数来实现:
Private Sub Command1_Click()
ostr = "0123456789"
ostr = repl(ostr, 8, "x")
Print ostr
End Sub

Public Function repl(str1, x, str2)
'str1---源字符串,x---待替换位置,str2---新字符串
If x > Len(str1) Then Exit Function
repl = Mid(str1, 1, x - 1) & str2 & Mid(str1, x + 1, Len(str1) - x)
End Function

回答2:

用Substring找出字串,再连接字符串用算法实现。。。因为c#封装了指针所以没办法直接改。但是C++可以。