1. Are you ready for the Galaxy S20? Here is everything we know so far!

Does Android Studio provide a way to escape strings?

Discussion in 'Android Development' started by Stokestack, Jun 21, 2020.

  1. Stokestack

    Stokestack Lurker
    Thread Starter

    I have a long string, and the compiler's complaining that there are unescaped apostrophes in it.

    This seems like the kind of thing Android Studio should offer as a function: Escape this string.

    Does it?
     


  2. wseng92

    wseng92 Android Enthusiast

    Add \.

    Example:
    Code (Java):
    1. <string name="app_name">Stack\'s Answers</string>
     
    MrJavi and mikedt like this.
  3. Stokestack

    Stokestack Lurker
    Thread Starter

    The question is whether Android Studio provides a function to escape all necessary characters in a string at once, so you don't have to go through paragraphs of text and do it manually. Does your response answer that question?
     
  4. codesplice

    codesplice Elite Recognized Moderator
    Moderator

    I don't think I've seen any IDE which can automatically detect and escape single-quotes for you - if you know of one, please let me know so I can check it out.

    At any rate, I wasn't able to find anything in Android Studio to do that. I think you'll have to manually escape naughty characters by preceding them with a backslash, like @wseng92 suggested.
     
    MrJavi likes this.
  5. Stokestack

    Stokestack Lurker
    Thread Starter

    Thanks. I'm not expecting anything automatic. I just want to highlight a block of text and then hit a hotkey or go to a menu and say "Escape string."
     
  6. mikedt

    mikedt 你好

    I'm not a dev myself of course and I've never used AS, but does the code editor in Android Studio not provide a global "FIND > REPLACE" function, like just about all decent word-processor and text editing software has? Where you can set it to find a specific string of characters and have it automatically replace them with something else, i.e. have it search your code and FIND these "unescaped apostrophes" and it REPLACE with the your appropriate escape string or whatever.
     
    MrJavi likes this.
  7. Stokestack

    Stokestack Lurker
    Thread Starter

    It does, but then you have to try every possible illegal character and do a global replacement for each one. It's not just apostrophes.
     
Loading...
Similar Threads - Does Android Studio
  1. akaskhu
    Replies:
    2
    Views:
    342
  2. angrypidgeon
    Replies:
    6
    Views:
    466
  3. chinnar
    Replies:
    0
    Views:
    471
  4. akaskhu
    Replies:
    4
    Views:
    474
  5. akaskhu
    Replies:
    3
    Views:
    452
  6. idon
    Replies:
    0
    Views:
    479
  7. idon
    Replies:
    1
    Views:
    359
  8. CursedAndroid
    Replies:
    10
    Views:
    562
  9. HimanshuB7
    Replies:
    3
    Views:
    428
  10. RewindJAA
    Replies:
    0
    Views:
    1,689

Share This Page

Loading...