按字符分割字符串 [英] Split String By Character
本文介绍了按字符分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个字符串,让我们调用的是文本",我想将其拆分为每个字符,但还要删除空格.如果您无法擦除空格,则可以在另一个代码段中完成自己的工作.可以说文本"等于"Hello World",我希望输出代码为:
hey guys,
i have a string, lets call is ''text'' and i want to split it into every character but also erase the spaces. If you can''t erase the spaces, i can do that my self in another code piece. lets say that ''text'' is equal to ''Hello World'', i wand the output code to be:
h
e
l
l
o
w
o
r
l
d
推荐答案
尝试:
Dim myString As String = "Hello World"
Dim withNoSpaces As String = myString.Replace(" ", "")
For Each c As Char In withNoSpaces
Console.WriteLine(c)
Next
作为替代,您始终可以使用RegEx.Split
. 此 [
As an alternate, you can always use RegEx.Split
. This [^] may help. In particular, look at the last example given on that link.
这篇关于按字符分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文