开发者

C# Splitting Strings on `#` character

开发者 https://www.devze.com 2023-04-07 11:53 出处:网络
just wondering for example, if I had the string: Hello#World#Test How would I remove the # and then have Hello开发者_C百科, World and Test in three seperate strings, for example called:

just wondering for example, if I had the string:

Hello#World#Test

How would I remove the # and then have Hello开发者_C百科, World and Test in three seperate strings, for example called: String1 and String2 and String3


You can have them in an array of strings doing something as easy as this:

string[] s = "Hello#World".Split('#');

s[0] contains "Hello", and s[1] contains "World"

See here for more information on split: http://msdn.microsoft.com/en-us/library/b873y76a.aspx


String.Split("#".ToCharArray()) will return a string[] with two elements.

Element0 will be "Hello", and Element1 will be "World"


This is one way

"hello#world".Split('#');
0

精彩评论

暂无评论...
验证码 换一张
取 消