Skip to main content
Topic: Key characters (Read 105468 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Key characters

So we know you can use characters like so "\224"

So if i wanted to write that out in a textbox that the user controls, then take that string to add that character, how would i?

It seems to refuse "/" because it is a special character (ie appears replaced by the appropriate character)

so "\" + "224"
would not work because it wont accept "\" on its own?

any ideas?

Re: Key characters

Reply #1
You would have to do the conversion yourself, e.g.

Code: [Select]
function convert(text) {
  return text.replace(/\\([\d]+)/, function (match) {
    return String.fromCharCode(match.substr(1));
  });
}


This would convert a backslash followed by any numbers to the corresponding ASCII character, so convert("\\65") in JS (typed in your game that would be "\65") results in "A".

Re: Key characters

Reply #2
thanking you :)

Re: Key characters

Reply #3
@casiotone: That should probably be /\\(\d+)/g. You don't need the brackets around the \d and you need /g to replace all.

EDIT - thanks Radnen... not sure how I didn't notice that :P

Re: Key characters

Reply #4
Alpha: you mean @casiotone the other admin.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here


Re: Key characters

Reply #6
I keep hitting modify instead of quote. I hate being an admin.

Quote from: alpha123
That should probably be /\\(\d+)/g. You don't need the brackets around the \d and you need /g to replace all.

whoops, yes. When I was writing it I was going to use the match group but substr on the full match was easier.

Quote from: alpha123
Who was casiotone on the old forums? I don't remember him.

:-X


Re: Key characters

Reply #8

I keep hitting modify instead of quote. I hate being an admin.


Ha, tell me about it, I made the same mistake too, luckily I never committed any of those modified messages. :P
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here