Separate string by tab characters

后端 未结 3 2035
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 00:11

I have a text file that is tab-delimited. How can I separate this string into substrings for an array by detecting the tabs?

相关标签:
3条回答
  • 2020-12-11 00:12

    If you use String.split() you can split the String around any regular expression, including tabs. The regex that matches tabs is \t, so you could use the following example;

    String foo = "Hello\tWorld";
    String[] bar = foo.split("\t");
    

    Which would return a String array containing the words Hello and World

    0 讨论(0)
  • 2020-12-11 00:25
    string s = "123\t456\t789";
    string[] split = s.Split('\t');
    
    0 讨论(0)
  • 2020-12-11 00:35

    Just use the String.Split method and split on tabs (so probably first one split on newlines to get the lines and then one on tabs to get the values).

    See here for details:

    http://msdn.microsoft.com/en-us/library/system.string.split.aspx

    0 讨论(0)
提交回复
热议问题