开发者

trim a string in jquery

i need to trim a string to its first 100 characters using jquery/javascript.

also is it possible to scan a开发者_C百科 string and look for a particular combination of keywords such as #key?

thanks a lot for the help.


To keep only the first 100 characters of a string use substring:

s = s.substring(0,100)

To search for a substring use indexOf:

s.indexOf("#key")


To answer your first question, regular JavaScript will do just fine:

 var trimmed = MyString.substr(0, 100);

To your second, you can use regular expressions to scan for patterns: http://www.regular-expressions.info/javascript.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜