How to put " in a String?

Asked

Viewed 1,218 times

1

I’m trying to evaluate a PHP code using Java, for that I need to replace in the code all " for \". The problem is that Java also has this escape character to put " in a String. Told me to use \\", but the result was this:

inserir a descrição da imagem aqui

Does anyone know how to type this? Or any way to run PHP inside the JVM? (I’m doing a trick that boils down to running on the terminal echo "codigo" | php... It’s working, but there’s this little problem with "). Thank you

  • Beware of evaluating codes. If you have any possibility of user input, your program may have a high risk of vulnerability.

  • Try to use \\\", The first two bars will be transformed into one for the string, and the \" will be the literal character ".

  • Was solved using \\\", Thank you guys. As for the "evaluator" care, I have a handle on this, thank you for warning =)

  • @Mateusa., put your comment in response, so Nathan can mark it as correct, thus helping the community.

  • 2
  • 1

    To run PHP in the JVM: http://j-php.net/

  • Vote today! Vote tomorrow! Vote forever! Vote consciously! Your vote is very important to our community, contribute to us, and help make Stack Overflow in Portuguese (Sopt) bigger and bigger. You can learn more at: Vote early, vote often

Show 2 more comments

1 answer

1

Try to use \\\", the first two bars will be transformed into one, for the string, and the \" will be the literal character ".

  • Ué, the answer is in the answer not in the comments. I did not understand the -1

  • 1

    I think it was because it would be more friendly of you to guide to Your turn comment in response than to copy his comments in full ;)

  • That may be, but if Matthew puts the answer, I remove mine from the good ones, instead of being negatived by an answer that is correct :|

  • That’s why I said "guide you to convert the comment in response" ;)

  • Because they didn’t guide me yet, instead of negatively ?

  • Why didn’t you guide him? This is something that anyone can do, including shows companionship :)

  • 1

    Yes, I did now! While you were telling me to do :D

  • 1

    No need for -1, this question is very simple and has already been answered here and here for this reason I did not answer and I marked as comment, besides being able to cover another answer because it does not show the complete code. My only mistake was not signaling, sorry... but can keep the answer.

  • 1

    Since I entered the stack here, I do not understand the people responding in the comments, seriously. Comment is to comment, reply to reply. Why this craze?

  • 1

    @Lucashenrique got this craze in the O.R., and they can be for several motives.

  • 1

    @Mateusa. I think I understood, it would be like, I don’t have time to give a detailed answer, I’m not sure if it’s totally correct, or just to give a guide to the right way.

  • @Lucashenrique yes, so much so, as also do not like to answer questions I signal (third answer of the post on goal).

  • @Mateusa. makes sense...

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.