Replacing Space character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • homesick123
    New Member
    • Oct 2006
    • 8

    Replacing Space character

    From the following pattern:

    $x = f+ remove/4occurances/of spaces/immediately/after plus

    There are 4 space characters after f+ which are to be removed .So
    How can I get the following :

    $x = remove/4occurances/of spaces/immediately/after plus
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Say you have the string: my $string = "foo f+ bar";

    To remove the 4 space characters after the substring "f+", all you need to do is:

    $string =~ s/f\+ {4}/f+/;

    The new value will be "foo f+bar";

    <Note>
    I'm not sure if that is what you wanted though. To more clearly ask how to make a regular expression, simply give the exact string you have before and what you want after. Alternatively, you could actually write out what you want using english, instead of this/wierd/slashing type/question. :)
    </Note>

    Comment

    Working...