By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

how to get indexOf some string from value

P: 77
hello i have this script in javascript type

Expand|Select|Wrap|Line Numbers
  1. delimiter = ".";
  2. formatCoa = "xxxx"+delimiter+"xxx"+delimiter+"xxx";
  3. alert(formatCoa.indexOf(delimiter));
  4.  
but the result is i only get the first indexOf delimiter, the result is 4.
And as you can see there is two delimiter in the formatCoa...

my question is, how can i get the other delimiter value of "indexOf"

thanks

kind regards,
maminx
Jul 24 '08 #1
Share this Question
Share on Google+
9 Replies


gits
Expert Mod 5K+
P: 5,343
that is correct ... read the summary for the indexOf() - method here ...

kind regards
Jul 24 '08 #2

P: 77
that is correct ... read the summary for the indexOf() - method here ...

kind regards

so sorry, the URL that u sent to me is blocked by our office, so sorry....but can you just tell me how can i solve my problem??

thanks

regards, maminx
Jul 25 '08 #3

P: 77
so sorry, the URL that u sent to me is blocked by our office, so sorry....but can you just tell me how can i solve my problem??

thanks

regards, maminx

to get the other delimiter value of "indexOf" as i wrote before above..

thanks
Jul 25 '08 #4

RamananKalirajan
100+
P: 607
Hi, What you had done is right but the thing is you have to implement a new logic, you got the first index but you are not getting the other two index.

ex: asdfh.aflkjfa.asfdf.adfasdf

Using indexOf() you got the first '.' position. What i can suggest is you just get the substring of that string from the place value like

ex:
var myString = "asdfh.aflkjfa.asfdf.adfasdf";
var firstDot = myString.indexOf(".");
var newString = myString.substring(firstDot+1,myString.length);
var secDot = newString.indexOf(".");

You can do this way and add firstDot, secDot u can get the place value of second Dot in original String.

If you are confused post your code i will fix it for u.

Regards
Ramanan Kalirajan
Jul 25 '08 #5

gits
Expert Mod 5K+
P: 5,343
a quite easy way would be just to loop through the string:

Expand|Select|Wrap|Line Numbers
  1. var s   = "xxxx.xxx.xxx";
  2. var pos = [];
  3.  
  4. for (var i = 0; i < s.length; i++) {
  5.     if (s[i] == '.') {
  6.         pos.push(i);
  7.     }
  8. }
  9.  
  10. alert(pos);
kind regards
Jul 25 '08 #6

RamananKalirajan
100+
P: 607
a quite easy way would be just to loop through the string:

Expand|Select|Wrap|Line Numbers
  1. var s   = "xxxx.xxx.xxx";
  2. var pos = [];
  3.  
  4. for (var i = 0; i < s.length; i++) {
  5.     if (s[i] == '.') {
  6.         pos.push(i);
  7.     }
  8. }
  9.  
  10. alert(pos);
kind regards

This is easier when compared to mine. Since my idea involves splitting of string.
You can use the code suggested by Mr. Gits.

Regards
Ramanan Kalirajan
Jul 25 '08 #7

gits
Expert Mod 5K+
P: 5,343
it is just a matter of performance by avoiding operations that are not needed and operations with strings are the ones that are the worst :) ... so everytime you have such tasks try to avoid splitting, merging etc. in case you don't really need it ...

kind regards
Jul 25 '08 #8

P: 77
it is just a matter of performance by avoiding operations that are not needed and operations with strings are the ones that are the worst :) ... so everytime you have such tasks try to avoid splitting, merging etc. in case you don't really need it ...

kind regards

thanks for all indeed...

kind regards,

maminx
Jul 25 '08 #9

RamananKalirajan
100+
P: 607
Whether you finished up with your work.

Regards
Ramanan Kalirajan
Jul 28 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.