如何从起始索引读取字符串
How to read a string from starting index
Dim text as string = "Visual Basic"
output: "Basic"
我需要读取一个字符串并打印它但不是从第一个索引开始。文本可能会有所不同,所以我想知道是否有阅读方法。
可以先用IndexOf
方法找到第一个space,再用SubString
方法得到space后面的部分字符串:
Dim idx As Integer = text.IndexOf(" "C);
Dim output As String = text.SubString(idx + 1);
(如果字符串中根本没有 space,这甚至有效。那么 idx
将是 -1
(值表示 "not found"),所以idx + 1
将是零,output
将是整个字符串。)
Dim text as string = "Visual Basic"
output: "Basic"
我需要读取一个字符串并打印它但不是从第一个索引开始。文本可能会有所不同,所以我想知道是否有阅读方法。
可以先用IndexOf
方法找到第一个space,再用SubString
方法得到space后面的部分字符串:
Dim idx As Integer = text.IndexOf(" "C);
Dim output As String = text.SubString(idx + 1);
(如果字符串中根本没有 space,这甚至有效。那么 idx
将是 -1
(值表示 "not found"),所以idx + 1
将是零,output
将是整个字符串。)