Mask Characters in a word

11 views
Skip to first unread message

Godwin

unread,
Mar 21, 2014, 3:53:00 AM3/21/14
to codenameone...@googlegroups.com
I want to replace some characters in a word with "*". I tried using the StringBuilder  class but I got the error message :

 error: cannot find symbol
                   
String test = String.valueOf(builder.replace(1, 2, "*"));
  symbol
:   method replace(int,int,String)
  location
: variable builder of type StringBuilder

this is what I did:

StringBuilder builder = new StringBuilder(tempWord);
String test = String.valueOf(builder.replace(1, 2, "*"));

I tried using StringUtil class but there is no method to replace a characters by positions. How can I achieve this?

Shai Almog

unread,
Mar 21, 2014, 12:57:11 PM3/21/14
to codenameone...@googlegroups.com
You will need to do something like:
String test = s.substring(0, 1) + "*" + s.substring(2, s.length());

Reply all
Reply to author
Forward
0 new messages