开发者

trim a string in jquery

开发者 https://www.devze.com 2022-12-25 01:37 出处:网络
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?

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

精彩评论

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