在vb.net中添加一个字符串的空间 [英] add space of one character string in vb.net
问题描述
我在vb.net中有一个字符串:
Hi,
I have a string in vb.net as:
Dim MyString As String = ""
在我执行的执行中字符串的结果如下:
In the execution i got the string result in the following manner:
MyString = 1|2|3|4|5|6|7|8|9|1|2|3|4|5|6|7|8|9
所以我希望在字符串9 | 1之间有空格,例如
so what i want to have a space between the string 9|1 like for e.g.
1|2|3|4|5|6|7|8|9 |1|2|3|4|5|6|7|8|9
怎么办?
接下来的问题是在字符串中假设9后我必须创建单个字符空间并删除|符号我该怎么办?谢谢。
How can do so?
Next question is that in the string suppose after 9 i have to make a single character space and remove | symbol how can i do so? Thanks.
1|2|3|4|5|6|7|8|9|1|2|3|4|5|6|7|8|9
i:我如何删除字符并在确定数字或点后的数字之间添加空格
i:e how can i remove the character and add space between the number after a definite number or poin
推荐答案
有一个你可以做多少种方法,范围从简单化
There are a number of ways you can do it, ranging from the simplistic
MyString = MyString.Replace("9|1", "9 |1")
正如ryanb31所建议的,
通过使用MyString.IndexOf和MyString.SubString(谷歌和MSDN可以帮助你):
as has been suggested by ryanb31,
through use of MyString.IndexOf and MyString.SubString (Google, and MSDN can help you with them):
Dim MyString As String = "1|2|3|4|5|6|7|8|9|1|2|3|4|5|6|7|8|9"
Dim index As Integer = MyString.IndexOf("9|1")
If index >= 0 Then
Dim left As String = MyString.Substring(0, index)
Dim right As String = MyString.Substring(index + 3)
MyString = left & "9 |1" & right
End If
通过MyString.Split和String.Join(谷歌再次),到Regex(有关于此的全书)。
究竟哪个解决方案适合您,取决于太多因素:字符串的变量,您希望完成替换的次数,以及您需要将其设置为9 | 1的灵活性。
through MyString.Split and String.Join (Google again), to Regex (there are whole books about this).
Exactly which solution is right for you, depends on too many factors: how variable the string is, how many times you want the replacement done, and how flexible you need to be about it being "9|1".
>
这篇关于在vb.net中添加一个字符串的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!