I know that js substring
method accept number parameters but what if I need to get a part of string beginning with ?
. So the method must accept a char value for beginning position. How can I do this?
Asked
Active
Viewed 56 times
0

Jonathan Hall
- 75,165
- 16
- 143
- 189

rozerro
- 5,787
- 9
- 46
- 94
-
1You can find the position with `indexOf`and after that you can get the string with `substing` – TheBrain Jan 25 '16 at 19:43
-
1http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – balping Jan 25 '16 at 19:46
-
Read the documentation of the methods available on strings at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String. – Jan 25 '16 at 19:55
2 Answers
0
Something like this should get you the results (unless I am understanding your question incorrectly, apologies if I did):-
index = myString.indexOf("?");
var mysubString = "";
if(index == 0) //<--- only for strings that are beginning with a "?"
{
mysubString = myString.Substring(1, myString.length);
}
this should get you a string that starts with a "?" but without displaying the "?" as part of your substring...until the end of the string.

Philo
- 1,931
- 12
- 39
- 77
0
You could use the indexOf
method so that you know where is the "?"
char.
var test = "is this a test? Yes it is!";
var startAt = test.indexOf('?') + 1; // + 1 so that '?' is not returned
test.substring(startAt);

Cristiano Mendonça
- 1,220
- 1
- 10
- 21
-
for some reason I get `Uncaught TypeError: uri.indexOf is not a functionrefreshByHash @ search_pagin_script.js:12x.event.dispatch @ jquery-1.10.2.min.js:5v.handle @ jquery-1.10.2.min.js:5` – rozerro Jan 25 '16 at 20:12