I have a text file with lines of something like this:
(LIST (LIST 'Abbott 'Ashley 'J ) '8697387888 '[email protected] 2.3073320999676614 )
I have read the file into individual string array elements, but I want to split into individual array elements so it is more useful like:
|Abbott|Ashley|J|8697387888|[email protected]|2.3073320999676614|
However, I can't figure out how to do this. Here is what I have tried, but doesn't work due to syntax.
for (int Count = 0; Count < lines.Length; Count++)
{
Split = lines[Count].Split(''');
}
I'm trying to use the single quotes as the split break.
Use method String. split() It returns an array of String, splitted by the character you specified.
This variant of the split method takes a regular expression as a parameter and breaks the given string around matches of this regular expression regex. Here, by default limit is 0. Returns: An array of strings is computed by splitting the given string.
This variant of the split method takes a regular expression as a parameter and breaks the given string around matches of this regular expression regex. Here, by default limit is 0. Returns: An array of strings is computed by splitting the given string. Throws: PatternSyntaxException – if the provided regular expression’s syntax is invalid.
Following are the two variants of split() method in Java: Parameters: regex - a delimiting regular expression Limit - the result threshold Returns: An array of strings computed by splitting the given string. Throws: PatternSyntaxException - if the provided regular expression’s syntax is invalid.
The choice between both the types (single quotes and double quotes) depends on the programmer’s choice. Generally, double quotes are used for string representation and single quotes are used for regular expressions, dict keys or SQL.
Try using a \
.
Split = lines[Count].Split('\'');
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