문제

I need to replace last word from input value

Im using this code,

Get_value =$(input).val();
new_word= "new word";

function ReplaceLastWord(Get_value, new_word) {
 return Get_value.replace(/\w*$/, new_word);
}

$(input).val(ReplaceLastWord(Get_value, new_word));

Its working, but only for english... i am using tamil laguage in input

$(input).val()="கோச்மேடிக்ஸ் ச்னக்க்ஸ்";

For this language i need use this code.

도움이 되었습니까?

해결책

try this

     var lastWord = function(inputString,newstring) {
     inputString=inputString.replace((""+inputString).replace(/[\s-]+$/,'').split(/[\s-]/).pop(),newstring)
     alert(inputString);
};

lastWord("கோச்மேடிக்ஸ் ச்னக்க்ஸ்",'hi');

​ ​

Live Demo

here inputString is input value and and newstring is word to replace with.

if this will help you mark this as answer

다른 팁

function ReplaceLastWord(Get_value, new_word) {
 return Get_value.substring(Get_value.lastIndexOf(" ") + 1) + new_word;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top