字符串的一些操作
2008-02-23 06:52:01来源:互联网 阅读 ()
Public Function sCount(String1 As String, String2 As String) As Integer
Dim I As Integer, iCount As Integer
I = 1
Do
If (I > Len(String1)) Then Exit Do
I = InStr(I, String1, String2, VBTextCompare)
If I Then
iCount = iCount 1
I = I 2
DoEvents
End If
Loop While I
sCount = iCount
End Function
□ 怎样在一个字符串中完全删除里面的另外一个字符串?
Function StringCleaner(s As String, _
Search As String) As String
Dim i As Integer, res As String
res = s
Do While InStr(res, Search)
i = InStr(res, Search)
res = Left(res, i - 1) & _
Mid(res, i 1)
Loop
StringCleaner = res
End Function
□ 怎样在一个字符串中删除里面的另外一个字符串?
Public Sub sRemove(String1 As String, String2 As String)
Dim I As Integer
I = 1
Do
If (I > Len(String1)) Then Exit Do
I = InStr(1, String1, String2)
If I Then
String1 = Left$(String1, I - 1) Mid$(String1, I Len(String2) 1)
I = I 2
DoEvents
End If
Loop While I
End Sub
□ 怎样在一个字符串中替换里面的另外一个字符串?
Public Sub sReplace(String1 As String, String2 As String, RepString As String)
Dim I As Integer
I = 1
Do
If (I > Len(String1)) Then Exit Do
I = InStr(1, String1, String2)
If I Then
String1 = Left$(String1, I - 1) RepString Mid$(String1, I Len(String2) )
I = I 2
DoEvents
End If
Loop While I
End Sub
□ 如何计算一个字符串中的行数?
Function CountStringLine(src_string As String) As Integer
On Error Resume Next
Dim string_flag As Integer
Dim line_cnt As Integer
Dim test_string As String
line_cnt = 0 '初始--> 行数为1
string_flag = 1 '标志为1
test_string = src_string
DoEvents
Do
line_cnt = line_cnt 1
string_flag = InStr(test_string, vbCrLf) '判断回车换行
test_string = Right(test_string, Len(test_string) - string_flag - 1)
Loop Until string_flag <= 0
CountStringLine = line_cnt
End Function
□ 如何从一个字符串中读取一行字符?
Function ReadStringLine(src_str As String, lineno As Integer) As String
On Error Resume Next
Dim string_flag As Integer
Dim line_cnt As Integer
Dim test_string As String
Dim ret_string As String
line_cnt = 0 '初始--> 行数为1
string_flag = 1 '标志为1
test_string = Right(src_str, 2)
If test_string <> vbCrLf Then
test_string = src_str vbCrLf
Else
test_string = src_str
End If
DoEvents
Do
line_cnt = line_cnt 1
string_flag = InStr(test_string, vbCrLf)
ret_string = Left(test_string, string_flag)
test_string = Right(test_string, Len(test_string) - string_flag - 1)
Loop Until lineno <= line_cnt
'If line_cnt = 1 Then
' ReadStringLine = ret_string
'Else
ReadStringLine = Left(ret_string, Len(ret_string) - 1)
'End If
End Function
上一篇: “会报数的计算器”的基本实现
下一篇: 鼠标编程小技巧二则
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:VB中实现图像特技(2)
下一篇:VB给菜单加上图片
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash