Using the .NET MicroFramework which is a really cut-down version of C#. For instance, System.String barely has any of the goodies that we've enjoyed over the years.
I need to split a text document into lines, which means splitting by \r\n. However, String.Split only provides a split by char, not by string.
How can I split a document into lines in an efficient manner (e.g. not looping madly across each char in the doc)?
P.S. System.String is also missing a Replace method, so that won't work.
P.P.S. Regex is not part of the MicroFramework either.
To split a string in R, use the strsplit() method. The strsplit() is a built-in R function that splits the string vector into sub-strings. The strsplit() method returns the list, where each list item resembles the item of input that has been split.
Strsplit(): An R Language function which is used to split the strings into substrings with split arguments.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
You can do
string[] lines = doc.Split('\n');
for (int i = 0; i < lines.Length; i+= 1)
lines[i] = lines[i].Trim();
Assuming that the µF supports Trim() at all. Trim() will remove all whitespace, that might be useful. Otherwise use TrimEnd('\r')
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