如何在 VB.NET 中检测字符串中的特定字符?
好的,所以在我正在 VB.NET 中编写的程序中,我尝试制作它,以便可以接收字符串列表(每个字符串位于不同的行)。对于每一行,我想将其分成三部分。第一部分从字符串的开头到字符串中的第一个冒号,第二部分从第一个冒号到 at 符号,最后一部分从 at 符号到字符串的末尾。
例如,我会采用一系列行中的一行: hello:world@yay
我想将其分成三个单独的字符串“hello”、“world”和“yay”。
我该如何在 VB.NET 中做这样的事情呢?
Okay, so in a program I'm working on in VB.NET I'm trying to make it so I can take in a list of strings (each on a different line). For each line I want to take in the line, and break it up into three parts. The first part goes from the beginning of the string to the first colon in the string, the second part goes from the first colon to the at symbol, and the last part goes from the at symbol to the end of the string.
For example, I'd take in a line of the series of lines:
hello:world@yay
I'd want to break it into three separate strings of "hello", "world", and "yay".
How would I do such a thing in VB.NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过
Split
来完成此操作。出于示例目的,我正在重新分割一个本来可以保存的字符串,因此我不必再次Split
它。但是,这样理解更简单:如果您正在读取文本文件,例如
You can accomplish this with a
Split
. For example purposes, I am re-splitting a string which I could have saved off, so I wouldn't have toSplit
it again. However, it's simpler to understand this way:If you're reading from a text file, e.g.
使用 split 命令
首先使用“:”,然后用“@”分割第二个编辑元素
Use the split command
Start by splitting the string with the ":" and then split the second edit element with the "@"
查看 string.indexOf 并从那里获取它
Look at string.indexOf and take it from there