Java to remove non-alpha characters

 2 Replies
 0 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
MC
Advanced Member
Posts: 41
Advanced Member
    I need a Java routine that I can put in to my PF to remove the non a-z charaters (upper and lower) from the employee name and compress the remaing good characters into a string.

    Kyle Jorgensen
    Veteran Member
    Posts: 122
    Veteran Member
      I presume you mean javascript.
      Use the string replace method combined with a regular expression.
      See www.w3schools.com for a very easy to navigate and thorough reference to the javascript language.
       
      var strString = "My Name";
      var strJustUppers = strString.replace(/[a-z]/g,""); // replace lower case letters with nothing
      var strJustUppers = strJustUppers.replace(/\s/g,""); // replace spaces with nothing
      

      After the code above execute, the variable strJustUppers should have the value of "MN".
      MC
      Advanced Member
      Posts: 41
      Advanced Member
        thanks so much, I was able to use this:

        AlphaLastName.replace(/[^a-zA-Z]/,"") it is more than just spaces, need to get rid of dash..apostrophe and all the 'funky' characters in the last name