I cant get this to work it doesnt replace all the special character and white spaces?
String sentence = "!##$%ˆ&*()<>?:"{} Hello ";
String newSentence = sentence.replaceAll("\\W+","").toLowerCase();
print(newSentence);
Use
String sentense = '!#resu##me'.replaceAll(new RegExp('\\W+'), '');
print(sentense);
Output:
resume
For more reference https://api.dart.dev/stable/2.8.3/dart-core/String/replaceAll.html
You should try this:
String sentence = "!##\$%ˆ&*()<>?:\"{} Hello ";
String newSentence = sentence.replaceAll(RegExp(r'[^a-zA-Z0-9 ]'),"").toLowerCase();
print(newSentence);
Related
I have this string ffff #fgggg #, How can I do substring last #, Thats mean When I am using this code:
String text = `ffff #fgggg #`;
selectedUser = text.substring();
I expect selectedUser be == "";
I want to check text from last # ? If after last # be nothing, substring() method return "" ?
I found answer :
selectedUser = text.substring(text.lastIndexOf('#') + 1);
and I got "". It checked from last #.
Looking for RegExp to remove text between parentheses in dart/flutter. For example
Input...
Test Message (To Be removed)
Output
Test Message
String str = "Test Message (To Be removed)";
str.replaceAll(RegExp(<regular-expression>), '');
Hi You can use this RegExp
String str = "Test Message (To Be removed)";
var test = str.replaceAll(RegExp('\\(.*?\\)'), '');
print(test);
Another RegExp
RegExp(r'\((.*)\)')
How I will find the last text between two or three text
I/p:
String text='Hello Monkey';
String text='Hello hi Monkey';
op:
Monkey
Monkey
You can try with below lines
String text='Hello hi Monkey';
print("Lst Word: ${text.substring(text.lastIndexOf(" "))}");
print("First Word: ${text.split(" ")[0]}");
I hope this will work for you
String text='Hello Monkey';
List<String> words = text.split(" ");
print(words.last);
using Dart How to remove space at the beginning and end of a string?
String name =" Well Wisher ";
or this
String name =" Well Wisher";
or from this
String name ="Well Wisher ";
Thanks #https://stackoverflow.com/users/5882307/omi-shah
the .trim() function is used to remove white space from the front and end of a string
String name =" Well Wisher ";
name.trim(); // "Well Wisher"
I am printing code to a TextMesh, and it is always changing. I need to save the string to a PlayerPref, so that I can load it back up. In order to get the text to fit properly, I have to force a line break in the string, using \n.
string text = "line1\nline2";
PlayerPref.SetString("Text", text);
LocationSide1.GetComponent<TextMesh>().text = PlayerPrefs.GetString("Text");
If I set the text without the PlayerPref it will do a line break:
line1
line2
With the PlayerPref it prints as one line:
line1\nline2
Any ideas on how to fix this?
Seems like the '\' is escaped.
Have you tried to unescape the string ?
using System.Text.RegularExpressions;
[...]
string text = "line1\nline2";
PlayerPref.SetString("Text", text);
LocationSide1.GetComponent<TextMesh>().text = Regex.Unescape(PlayerPrefs.GetString("Text"));
myString = Regex.Unescape(myString);