For a code generation tool I’m working on, I need to take a string and generate a valid java variable name from it, but I’m not sure about the best way to do it.
For example:
"123 this is some message !" => _123_this_is_some_message ( or something similar)
Thanks
Assuming you replace all invalid characters by
_something like the code below could work (rough example). You might want to add some logic for name collisions etc. It is based on the JLS #3.8: