string[] SplitEquationText = EquationBox.Text.Split('');

in that line of code, it will not let me split nothing? am i allowed to split nothing?
thank you.

Edited by choover12: n/a

6 Years
Discussion Span
Last Post by __avd

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.

Edited by Momerath: n/a


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;
     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.

i know how to spit. i just want something like "Hello World" to look like: "H e l l o W o r l d" so i could remove something from it. i could do if (this.Contains("this")) but it would not work.


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.


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 + " ";

Edited by Mitja Bonca: n/a


Use string.Join method.

string text = "Hello World";
 string s=string.Join<char>(" ", text);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.