cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

How to correctly represent '\xa0' in Java to transpile to a js String with multiple whitespaces #543

Closed andrea-gasparini closed 4 years ago

andrea-gasparini commented 4 years ago

I'm using JSweet for an homework (so I can't directly write JavaScript code) and I'm stuck with a problem with whitespaces. I need a string with multiple whitespaces but it seems impossible to just concatenate more " " Strings because of JavaScript.

The final result should be a "masked" word for a sort of Hangman game, but I'm having like _ _ _ _ _ _ _ _ to represent the phrase best way and without a double whitespace in the middle it seems to be a single word. I thought to have find this solution but the \xa0 character doesn't exist in Java and I couldn't find anything similar.

lgrignon commented 4 years ago

Hello, Thanks for reporting. Is the problem that you cannot display your multiple spaces in HTML? Because in pure Javascript it's totally possible to have a string containing multiple spaces.

var s = "l     o";
console.log(s)
> "l     o"

If this is about HTML display, as specified in your SO thread, you can use the special   entity.

Please reopen if your problem wasn't the one I mentionned.