I want to remove the the 3rd character, If the 3rd character(index) of the String is "0".
for example
String a = "850666";
String b = "8526668";
I want to get 85666
as "a" and 8526668
as "b"
(Length of Strings are not same)
My try:
void checkNumber(String loginToken) {
if (loginToken[3] == "0") {
String first = loginToken.substring(0, 2);
String nd = loginToken.substring(4, loginToken.length - 1);
String finalone = first + nd;
showSnackBarGreen(context, finalone, finalone);
}
}
It does not work perfectly, help me to continue
2
Answers
First of all, remember to check if the input length is less than 3 characters. Next, check the value of the 3rd element, then use
String::replaceRange()
to remove it. I’ve written a functionprocess
for you as a demo, as well as a few test cases to run it.Sample output: