I’m trying to find a forward slash in a string…
This doesn’t seem to work:
if ("/test".indexOf("/") > -1) {
What am I doing wrong?
Funny thing is… I tried this:
if ("!test".indexOf("!") > -1) {
and it works! I also tried \/ for that… help?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To test if a String starts with a given character, use
charAt(0)to get that charracteror
startsWith(String)to check for more than one character (a String)EDIT:
use
trim()to delete leading and trailing spaces if needed: