2

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.

8
  • How do you define the string? Meaningful word? Commented Nov 29, 2013 at 2:31
  • What do you want to do with it ? Commented Nov 29, 2013 at 2:34
  • Give another example, I think it'd make things clearer. Commented Nov 29, 2013 at 2:36
  • Lets say the string is "hellogooddayhello". I want the machine to check if hello is found in the first few letters of the string. Commented Nov 29, 2013 at 2:38
  • @Deximat what do you mean? Commented Nov 29, 2013 at 2:46

2 Answers 2

2

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/

Sign up to request clarification or add additional context in comments.

2 Comments

can you please share it on jsfiddle?
Yours is clearly explained and with an example, you deserved it.
1

Do Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.