Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slicing a string in Dart

Tags:

dart

how do I slice a string in dart

Example: "+5124343545" I want to remove the first index(ie. the "+" sign). so output will look like "5124343545"

like image 592
Bruno Avatar asked Sep 05 '25 03:09

Bruno


1 Answers

void  main() {
  String string = '+5124343545';
  string = string.substring(1);
  print(string);
}

Output: 5124343545 Or maybe you want to do the following:

void main() {
  String string = '+5124343545';
  string = string.replaceFirst('+','');
  print(string);
}

In the second variant you have no risk to delete number instead plus symbol (if the input variable didn`t have a plus in the first position).

like image 79
Makdir Avatar answered Sep 07 '25 20:09

Makdir