Substitute UC with space UC

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flamencoman@earthlink.net

    Substitute UC with space UC

    Hi,

    Can any one help:

    I am trying to replace a strings uppercase letters with a space upper
    case letter.

    For example, given the string "GeneralPartsLi st", I want to get the
    string " General Parts List".

    I tried:

    $mystring = "GeneralPartsLi st";

    if($mystring =~ /[A-Z]/)
    {
    $mystring =~ s/[A-Z]/ [A-Z]/g;
    }

    but I got an empty string.

    Thanks,

    Flamencoman
  • Jürgen Exner

    #2
    Re: Substitute UC with space UC

    flamencoman@ear thlink.net wrote:[color=blue]
    > I am trying to replace a strings uppercase letters with a space upper
    > case letter.
    > For example, given the string "GeneralPartsLi st", I want to get the
    > string " General Parts List".
    >
    > I tried:
    >
    > $mystring = "GeneralPartsLi st";
    > if($mystring =~ /[A-Z]/) {
    > $mystring =~ s/[A-Z]/ [A-Z]/g;
    > }
    >
    > but I got an empty string.[/color]

    Really? When I ran you program I got
    [A-Z]eneral [A-Z]arts [A-Z]ist
    which is what I would have expected.

    What about a simple
    $_ = "GeneralPartsLi st";
    s/([A-Z])/ $1/g;

    jue


    Comment

    • flamencoman@earthlink.net

      #3
      Re: Substitute UC with space UC

      On Sun, 07 Mar 2004 20:02:09 GMT, "Jürgen Exner"
      <jurgenex@hotma il.com> wrote:
      [color=blue]
      >flamencoman@ea rthlink.net wrote:[color=green]
      >> I am trying to replace a strings uppercase letters with a space upper
      >> case letter.
      >> For example, given the string "GeneralPartsLi st", I want to get the
      >> string " General Parts List".
      >>
      >> I tried:
      >>
      >> $mystring = "GeneralPartsLi st";
      >> if($mystring =~ /[A-Z]/) {
      >> $mystring =~ s/[A-Z]/ [A-Z]/g;
      >> }
      >>
      >> but I got an empty string.[/color]
      >
      >Really? When I ran you program I got
      > [A-Z]eneral [A-Z]arts [A-Z]ist
      >which is what I would have expected.
      >
      >What about a simple
      > $_ = "GeneralPartsLi st";
      > s/([A-Z])/ $1/g;
      >
      >jue
      >[/color]

      Jue,

      This works great thanks! I was getting an empty string because I left
      off the tilde in my actual code, so $mystring was not bound to the
      expression.

      Thanks,

      Flamencoman

      Comment

      Working...