Exactly what would it be splitting the string on? No, you can't split a string using no character.
I would really like to see an example of what you thought would happen.
Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
I will show you a sime example of to split array. Here you go:
//this is a button1_Click method, or could be even anything else:
string value = textBox1.Text;
if(value.Lenght > 0)
{
string[] array = value.Split(' '); //split by whitespace
string rows = null;
int i = 0;
while ( i < array.Lenght)
{
rows += array[i] + Environment.NewLine;
i++;
}
MesssageBox.Show("The mesage:\n" + + rows + "was split into " + array.Lenght.ToString() + " parts.");
}
Hope this helps you to understand the "split" method, using whitespace as splitter.
Mitja
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
I dont really understand you what you want now. What is exactly you are traing to achive?
Would you like from string "Hello World", change it to "H e l l o W o r l d"?
And what concerns your 1st question in your 1st post, YES, you are allowed to split nothing. If you have in mind example "thisIsTestString" - here is no white spaces, so code wont split - but there will still be NO error. There will be 1 array (same as 1 string), in a word - wortheless to have an array, but as said, no error - so you are allowed to split.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
For example how "Hello World" change to "H e l l o W o r l d":
string value = "Hello World";
char[] letters = value.ToCharArray();
string newValue = null;
foreach(char letter in letters)
{
newValue += letter + " ";
}
MessageBox.Show(newValue);
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
Use string.Join method.
string text = "Hello World";
string s=string.Join<char>(" ", text);
Console.WriteLine(s);
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241