-5

So I am trying to find a way to split strings into 2 different strings, example:
string str1 = "Hello there!";

then I want it to split it into 2 strings

string str2 = "Hello";
string str3 = "there!";

Thank you!

Here is the code I am using, I am pulling text from pastebin and trying to split it into multiple parts:

        WebClient client = new WebClient();
        string pulledInfo = client.DownloadString("https://pastebin.com/raw/cqmrCa0m");

        Console.WriteLine("Split with multiple separators");
        string gotInfo = pulledInfo;
        string[] multiArray = gotInfo.Split(new Char[] { ' ', ',',});
        foreach (string author in multiArray)
        {
            if (author.Trim() != "")
                Console.WriteLine(author);
        }

        Console.ReadKey();
jaabh
  • 815
  • 6
  • 22
Mr O
  • 1
  • 1

2 Answers2

0

You can get an array using string.Split():

string str1 = "Hello there!";
string[] text = str1.Split(' ');

string str2 = text[0];
string str3 = text[1];
Efraim Newman
  • 927
  • 6
  • 21
0
string str = "Hello there!";
string[] strings = str.Split(' ');
string yourstr1= strings [0];
string yourstr2= strings [1];
Alex
  • 21
  • 10