Home > Mobile >  How to remove number type inside text widget on flutter
How to remove number type inside text widget on flutter

Time:01-15

i have list text widget :

<Widget>((e)=> Text(e)).toList().

with value of e is : 123988montain

then how to remove number on list Text. i want that value on List Text show without number

CodePudding user response:

Simply use Regular expressions and it should work :

String text = '123988montain';
String newText = text.replaceAll(RegExp(r'[\d]'), '');
Text(newText);

You can also use replaceFirst instead of replaceAll function to remove only the first matched numbers

CodePudding user response:

You can use replaceAll extension on strings.

"123988montain".replaceAll(RegExp(r"[^a-zA-Z]"), ""); //Output : "montain"

"123988montain".replaceAll(RegExp(r"\d"), ""); //Output : "123988"

Or you can make a custom extension for strings on darts to remove the number from the string.

  • Related