Ich habe folgende Funktion
const cleanString=( string )=>{
let city = getAccentedCity(string = string.replace(/-/g, ' '));
let specialChrt = "%c3%9f" || "%20";
if( city.indexOf(specialChrt)<0 ) return city;
return city.replaceAll(specialChrt, ' ');
}
Wie kann ich das schreiben, wenn ich durch ersetzen möchte specialChrt
und nicht leer? Im Fall von ersetze ich gerne durch eine leere Zeichenfolge, wie es jetzt der Fall ist.%c3%9f
's'
"%20"
So habe ich es aufgeschrieben, wie kann ich es besser machen?
const cleanString=( string )=>{
let city = getAccentedCity(string = string.replace(/-/g, ' '));
let specialChrt = "%c3%9f" || "%20";
if(city.indexOf(specialChrt) < 0 ) {
return city;
} else if (city.indexOf("%c3%9f") > 0 ) {
return city.replaceAll(specialChrt, 's')
}
return city.replaceAll("%20", ' ')
}
Lösung des Problems
const cleanString = (string) => {
let city = getAccentedCity(string = string.replace(/-/g, ' '));
city = city.replaceAll('%20', ' ');
city = city.replaceAll('%c3%9f', 's');
return city;
}
Keine Kommentare:
Kommentar veröffentlichen