removing GBP symbol from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TonyN
    New Member
    • Jan 2009
    • 2

    removing GBP symbol from a string

    I have some code to adjust data entered into a web page template to use it in a javascript function. This, amongst other things, will remove start and end spaces, replace the inter-word spaces with hyphens, etc etc.

    However I am struggling to remove pound (£) signs.

    Is there something different that I need to do for currency symbols?

    Any help would be appreciated!

    Thanks

    Tony

    ------------------------------------------------------------
    Code:
    Here is the code for the other RegExs:
    $idref =~ s/\'//g; # remove '
    $idref =~ s/\&amp\; //g; # remove &amp;<space>
    $idref =~ s/\& //g; # remove &<space>
    $idref =~ s/\,//g; # remove ,
    $idref =~ s/\"//g; # remove "
    $idref =~ s/\-//g; # remove -
    $idref =~ s/\?//g; # remove ?
    $idref =~ s/ /_/g; # replace spaces with _
    Last edited by numberwhun; Jan 19 '09, 02:19 PM. Reason: Please use code tags
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by TonyN
    I have some code to adjust data entered into a web page template to use it in a javascript function. This, amongst other things, will remove start and end spaces, replace the inter-word spaces with hyphens, etc etc.

    However I am struggling to remove pound (£) signs.

    Is there something different that I need to do for currency symbols?

    Any help would be appreciated!

    Thanks

    Tony

    ------------------------------------------------------------

    Here is the code for the other RegExs:
    Code:
    $idref =~ s/\'//g; # remove '
    $idref =~ s/\&amp\; //g; # remove &amp;<space>
    $idref =~ s/\& //g; # remove &<space>
    $idref =~ s/\,//g; # remove ,
    $idref =~ s/\"//g; # remove "
    $idref =~ s/\-//g; # remove -
    $idref =~ s/\?//g; # remove ?
    $idref =~ s/ /_/g; # replace spaces with _
    You can try using the ascii character code to remove them. Also, please use code tags!

    Regards,

    Jeff

    Comment

    • TonyN
      New Member
      • Jan 2009
      • 2

      #3
      Thanks!

      Thanks, Jeff. that sent me off on the right direction - I'm sorted now :D


      p.s.
      This was my first post.. how should I be presenting code within a message?

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        Tony,

        You place your code inside of the &#91;CODE]&#91;/CODE] tags.

        --Kevin

        Comment

        • Kelicula
          Recognized Expert New Member
          • Jul 2007
          • 176

          #5
          FYI: You could also consider combining all those substitutions into one statement with a character class.

          [code=perl]
          $idref =~ s/\'//g; # remove '
          $idref =~ s/\&amp\; //g; # remove &amp;<space>
          $idref =~ s/\& //g; # remove &<space>
          $idref =~ s/\,//g; # remove ,
          $idref =~ s/\"//g; # remove "
          $idref =~ s/\-//g; # remove -
          $idref =~ s/\?//g; # remove ?
          $idref =~ s/ /_/g; # replace spaces with _

          # Change that into this:


          $idref =~ s/[',"-?&]|\&amp\;//g;
          $idref =~ s/\s/_/g;

          # untested.
          [/code]

          But of course that's just nit picking.

          Comment

          Working...