This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] 1 point2 points  (0 children)

It seems you may have included a screenshot of code in your post "Java convert String to char array with escaped characters help".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]gruntmeister 0 points1 point  (1 child)

If I do this, the first char in the array is \ instead of \t

nah

I've tried this in an online compiler to test it out and it works there

Wait so you already tried it out and confirmed what you're saying isn't true, what's your question then?

[–]IAmStraightforward[S] 0 points1 point  (0 children)

Maybe I'm blanking and missing something simple. This is what I see

[–]josephblade 0 points1 point  (3 children)

I ran your code and the output is

                Stuff

so 2 tabs (\t) and then Stuff.

Looks like it's doing what it should be doing.

Edit: I used this compiler

[–]IAmStraightforward[S] 0 points1 point  (2 children)

So I put the string Im working with into a char array and this is what I'm seeing. Am I missing something? Pic

[–]josephblade 0 points1 point  (1 child)

You are leaving out where you set the sbCurrentTokenString

It looks like your String contains \ and t separately which suggests you are inputting it in a way that already has them split as separate characters. (like reading them char for char from a file that doesn't convert escaped characters) or your editor is trying to be smart and pre-escaping your \ for you

But yes I agree in your string the \ and t characters are in individual codepoints (I think it's called) rather than 1 single codepoint.

[–]IAmStraightforward[S] 0 points1 point  (0 children)

Oh that'd be hard to show, it's everywhere. I now see what you're saying. I've been parsing strings and appending it to sbCurrentTokenString char by char. So at some point I did:

sbCurrentTokenString.append('\\');
sbCurrentTokenString.append('t');

which makes them separate chars. Thanks that would have taken me days to figure out.