07-21-2023, 07:32 PM
I am trying to replace only one character in a string dart but can not find any efficient way of doing that. As string is not array in Dart I can't access the character directly by index and there is no function coming in-built which can do that. What is the efficient way of doing that?
Currently I am doing that like below:
List<String> bedStatus = currentBedStatus.split("");
bedStatus[index]='1';
String bedStatusFinal="";
for(int i=0;i<bedStatus.length;i++){
bedStatusFinal+=bedStatus[i];
}
}
index is an **int** and **currentBedStatus** is the **string** I am trying to manipulate.
Currently I am doing that like below:
List<String> bedStatus = currentBedStatus.split("");
bedStatus[index]='1';
String bedStatusFinal="";
for(int i=0;i<bedStatus.length;i++){
bedStatusFinal+=bedStatus[i];
}
}
index is an **int** and **currentBedStatus** is the **string** I am trying to manipulate.