C# Textbox string separation

后端 未结 8 1517
遇见更好的自我
遇见更好的自我 2021-01-22 08:43

I have textbox in c#, contains two or three strings with white spaces. i want to store those strings seperately.please, suggest me any code. thanx.

相关标签:
8条回答
  • 2021-01-22 08:56
    string[] parts = myTextbox.Text.Split();
    
    0 讨论(0)
  • 2021-01-22 08:56
    string[] words =  Regex.Split(textBox.Text, @"\s+");
    
    0 讨论(0)
  • 2021-01-22 09:00
    var complexValue = @"asdfasdfsdf asdfasd fffff
    asdfasdfasdf";
    var complexValues = complexValue.Split();
    

    NOTICE:
    .Split() is a pseudo-overload, as it gets compiled as .Split(new char[0]).
    additionally msdn tells us:

    If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and return true if they are passed to the Char.IsWhiteSpace method.

    0 讨论(0)
  • 2021-01-22 09:04

    To get three different strings in an array, you can use String.Split()

    string[] myStringArray = OriginalString.Split(" ".ToCharArray());
    
    0 讨论(0)
  • 2021-01-22 09:05

    Firstly use this name space

    using System.Text.RegularExpressions;
    

    in your code

     string Message = "hi i am fine";
     string []Record=Regex.Split(Message.Trim(), " ");
    

    Output is an array. I hope it works.

    0 讨论(0)
  • 2021-01-22 09:09

    Try :

        string data = TextBox1.Text;
        var s1 = data.Split();
    
        string a = s1[0].ToString();
        string  b= s1[1].ToString();
    
    0 讨论(0)
提交回复
热议问题