How to remove a character from string and concatinate it in Dart | Flutter

Viewed 2508

I have two variables

String firstInput = "1.1.5";
String secondInput = "1.1.6";

From this I want the output firstOutput = 115 secondOutput = 116 How to remove dots from the string and concatenate remains as one variable ?

2 Answers

You can use the replaceAll method.
It would look like String out = firstInput.replaceAll(".","");

You can also use replaceAllwith RE as shown below

void main(){
  final myString = '1.3.4.6.6';
  String withoutDots = myString.replaceAll(RegExp('\\.'), ''); "Here \\ is used to as esc char"
  print(withoutDots); // prints 13466

}
Related