Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Test if string contains single backslash?

Guest
Oct 11, 2013 Oct 11, 2013

Hi

How would you do that?

I need to test if

a) the string contains two consecutive backslashes

b), if not, test if there is at least one backslash

if(test.indexOf("\\") >= 0) seems to hit on a string that's "ss\\ss", but I have a feeling that's incorrect. I think it's really just testing for 1 backslash.

And AS3 doesn't let you do if(test.indexOf("\") >= 0), as the single backslash escapes the rest of your code.

It's for testing the existance of either single or double backslashes in ID3 tags, as some editors use either as a delimeter for multiple tags within the one tag category eg genre: rock\\pop, or rock\pop

Thanks for taking a look.

TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 11, 2013 Oct 11, 2013

if(s.indexOf("\\\\")>-1){

//there are two or more consecutive backslashes

} else if(s.indexOf("\\")>-1){

// there is exactly one backslash

}

Translate
Community Expert ,
Oct 11, 2013 Oct 11, 2013

if(s.indexOf("\\\\")>-1){

//there are two or more consecutive backslashes

} else if(s.indexOf("\\")>-1){

// there is exactly one backslash

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 11, 2013 Oct 11, 2013

Cheers kGlad. Turns out double backslashes aren't getting picked up by the ID3 parser (Windows doesn't even seem to pick them up), but the single backslash works fantastic.

Much appreciated mate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2013 Oct 12, 2013
LATEST

this "\\" will be read as one backslash.  "\\\\" is two backslashes.  "\\\\\\" is 3 backslashes etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines