Separate string by tab characters

寵の児 提交于 2019-11-27 06:33:57

问题


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


回答1:


string s = "123\t456\t789";
string[] split = s.Split('\t');



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/2797647/separate-string-by-tab-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!