简体   繁体   中英

Javascript: Find string in first few letters

I would like to find the first a string in a string. I know it is not clear, so i decided to give an example.

For example, i got a string:

helloworld,hello

In "helloworld,hello", i want the system to find "hello" and ignore "world,hello". Is that possible?

If my question is unclear, do not refrain from asking me.

Thank you.

Please show me an example on how it works on jsfiddle.

Not without knowing what the content of the string will be. If you do know it, you could parse it with regex, like this: var patt1=/hello/; . This would find the first occurrence of hello.

jsfiddle: http://jsfiddle.net/x7WVP/

请尝试以下操作:

"helloworld,hello".match(/hello/).toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM