vbs教程《字串處理》

2021-07-25 17:01:55 字數 1685 閱讀 1614

rem 拆分字串

rem dim arr

rem arr = split("xiaohei,xiaobai,xiaoming", ",")

rem for each substr in arr

rem msgbox(substr)

rem next

rem 替換字串

rem msgbox(replace("xiaohei,xiaobai,xiaoming", ",", "|"))

rem 獲取子字串

rem msgbox(mid("xiaohei,xiaobai,xiaoming", 1, 7))

rem 修剪左空格

rem msgbox(ltrim(" xiaohei"))

rem 修剪右空格

rem msgbox(rtrim("xiaohei "))

rem 修剪左右空格

rem msgbox(trim(" xiaohei "))

rem 檢視子串位置

rem msgbox(instr("xiaohei,xiaobai,xiaobai,xiaoming", "xiaobai"))

rem msgbox(instr(10, "xiaohei,xiaobai,xiaobai,xiaoming", "xiaobai"))

rem msgbox(instr(30, "xiaohei,xiaobai,xiaobai,xiaoming", "xiaobai"))

rem 構造字串

rem msgbox(string(5, "x"))

rem 構造字串(空格組成)

rem msgbox("a" & space(5) & "b")

rem 左子串

rem msgbox(left("xiaohei,xiaobai,xiaoming", 7))

rem 右子串

rem msgbox(right("xiaohei,xiaobai,xiaoming", 8))

rem 字串長度

rem msgbox(len("xiaohei"))

rem 前字母對應的ansi字元**

rem msgbox(asc("xiaohei"))

rem ansi碼 to 字元

rem msgbox(chr(120))

rem 轉小寫

rem msgbox(lcase("xiaohei"))

rem 轉大寫

rem msgbox(ucase("xiaohei"))

rem 連線字串陣列

rem dim arr(3)

rem arr(0) = "xiaohei"

rem arr(1) = "xiaobai"

rem arr(2) = "xiaoming"

rem msgbox(join(arr, ","))

rem 比較字串(-1,0,1)

rem msgbox(strcomp("xiaohei", "xiaobai"))

rem msgbox(strcomp("xiaohei", "xiaohei"))

rem msgbox(strcomp("xiaobai", "xiaohei"))

rem 反轉字串

rem msgbox(strreverse("xiaohei"))

VBS 字串操作

vbs 字串操作 1.split expression,delimiter,count,compare 返回基於 0 的一維陣列,其中包含指定數目的子字串。expression 必選。字串表示式,包含子字串和分隔符。如果 expression 為零長度字串,split 返回空陣列,即不包含元素和資料...

字串處理 字串反轉

請原諒博主今天很閒,於是乎博主又開始更新微博了。這次要更新的問題是 編寫乙個函式,反轉乙個單詞的順序。例如 do or do not,there is no try.就要反轉成 try.no is there not,do or do 大家要認真看看這道題,這道題和大家想象的貌似有點不同。首先字串反...

字串處理

uncode與ansi字串轉換 我們使用windows函式multibytetowidechar將多位元組字串轉換成寬字元字串。函式如下 int multibytetowidechar uintcodepage dworddwflags lpcstrlpmultibytestr intcbmulti...