Skip to main content
Participant
February 4, 2007
Question

First 3 characters from the string and replace all with *

  • February 4, 2007
  • 3 replies
  • 455 views
Hello,

I am fairly new to coldfusion. I am trying to display the first 3 characters from string and replace all remaining characters with *(star). Could you please help with syntax? For ex: from the word 'hello' , I am trying to display this string like this. 'hel**'.

Thank you..
    This topic has been closed for replies.

    3 replies

    naveeAuthor
    Participant
    February 5, 2007
    Thank you. It worked fine. I appreciate your help.
    Inspiring
    February 4, 2007
    You don't need the loop you can just use the repeatString() function:-

    newstring = left(oldstring, 3);
    newstring = newstring & repeatString("*", len(oldstring) - 3);
    Inspiring
    February 4, 2007
    newstring = left(oldstring, 3);
    for (i = 1; i = len(oldstring) - 3; i = i + 1)
    newstring = newstring & "*";