Hi,

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.

Recommended Answers

All 6 Replies

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.

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

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 + " ";
}
MessageBox.Show(newValue);

Use string.Join method.

string text = "Hello World";
 string s=string.Join<char>(" ", text);
 Console.WriteLine(s);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.