How do I remove the newlines from a string in Dart?
For instance, I want to convert:
"hello\nworld"
to
"hello world"
We have used the replaceAll() method on string with RegEx expression to remove the special characters. It will give you the alphabets and numbers both and Special characters will be removed.
String s = "one. two"; //Removes everything after first '. ' String result = s. substring(0, s.
replaceAll method Null safety Replaces all substrings that match from with replace . Creates a new string in which the non-overlapping substrings matching from (the ones iterated by from. allMatches(thisString) ) are replaced by the literal string replace . Notice that the replace string is not interpreted.
You can use replaceAll(pattern, replacement):
main() { var multiline = "hello\nworld"; var singleline = multiline.replaceAll("\n", " "); print(singleline); }
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