字符串操作常用的例子
更好的 MID()
和其他字符串提取示例,目前缺少网络。请帮助我做一个很好的例子,或在这里完成这个。像这样的东西:
DIM strEmpty as String, strNull as String, theText as String
DIM idx as Integer
DIM letterCount as Integer
DIM result as String
strNull = NOTHING
strEmpty = ""
theText = "1234, 78910"
' -----------------
' Extract the word after the comma ", " and before "910" result: "78" ***
' -----------------
' Get index (place) of comma using INSTR
idx = ... ' some explanation here
if idx < ... ' check if no comma found in text
' or get index of comma using FIND
idx = ... ' some explanation here... Note: The difference is...
if idx < ... ' check if no comma found in text
result = MID(theText, ..., LEN(...
' Retrieve remaining word after the comma
result = MID(theText, idx+1, LEN(theText) - idx+1)
' Get word until the comma using LEFT
result = LEFT(theText, idx - 1)
' Get remaining text after the comma-and-space using RIGHT
result = ...
' What happens when things go wrong
result = MID(strNothing, 1, 2) ' this causes ...
result = MID(strEmpty, 1, 2) ' which causes...
result = MID(theText, 30, 2) ' and now...
result = MID(theText, 2, 999) ' no worries...
result = MID(theText, 0, 2)
result = MID(theText, 2, 0)
result = MID(theText -1, 2)
result = MID(theText 2, -1)
idx = INSTR(strNothing, "123")
idx = INSTR(theText, strNothing)
idx = INSTR(theText, strEmpty)
i = LEN(strEmpty)
i = LEN(strNothing) '...
请随意编辑此示例并使其更好。只要它仍然清晰,并且具有常见的使用方法。