I have a text file that is tab-delimited. How can I separate this string into substrings for an array by detecting the tabs?
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).
split() method to split a string by tabs, e.g. my_list = my_str. split('\t') . The str. split method will split the string on each occurrence of a tab and will return a list containing the results.
To split a string with specific character as delimiter in Java, call split() method on the string object, and pass the specific character as argument to the split() method. The method returns a String Array with the splits as elements in the array.
reqStr = Str.split(" ".ToCharArray)(2) Thanks for your quick response. Its not a space in each value, but its a tab space in each value. Can you please enter the tab space in each value and find out the value of 123. Screenshot for your reference.
string s = "123\t456\t789"; string[] split = s.Split('\t');
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With