나는 주어진 텍스트에 대해 모든 영어 이외의 문자를 적절한 문자로 변환하는 C# 함수를 사용합니다. 다음과 같이JavaScript를 사용하여 영어 이외의 문자를 영어로 변환하는 방법
public static string convertString(string phrase)
{
int maxLength = 100;
string str = phrase.ToLower();
int i = str.IndexOfAny(new char[] { 'ş','ç','ö','ğ','ü','ı'});
//if any non-english charr exists,replace it with proper char
if (i > -1)
{
StringBuilder outPut = new StringBuilder(str);
outPut.Replace('ö', 'o');
outPut.Replace('ç', 'c');
outPut.Replace('ş', 's');
outPut.Replace('ı', 'i');
outPut.Replace('ğ', 'g');
outPut.Replace('ü', 'u');
str = outPut.ToString();
}
// if there are other invalid chars, convert them into blank spaces
str = Regex.Replace(str, @"[^a-z0-9\s-]", "");
// convert multiple spaces and hyphens into one space
str = Regex.Replace(str, @"[\s-]+", " ").Trim();
// cut and trim string
str = str.Substring(0, str.Length <= maxLength ? str.Length : maxLength).Trim();
// add hyphens
str = Regex.Replace(str, @"\s", "-");
return str;
}
그러나 나는 클라이언트 측에서 javascript를 사용해야합니다. 위의 함수를 js로 변환 할 수 있습니까?
그것을 변환 확실히 가능
더 나은 제목이있을 수 있습니다. JavaScript를 사용하여 영어 이외의 문자를 영어로 변환하는 방법 –
예 Chris, 맞습니다. 나는 그것을 바꿨다. –