Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Strip leading spaces, reformat string

My program receives numbers that are 17 bites long, with leading spaces....For example,
$number1= "          -3.0000";
$number2= "        -127.0000";
$number3= "           2.5000";

If the number is negative, I need to print like this:
(3.0000) and (127.0000)

Is there a one liner to do this?  I have hundreds of numbers, what's speediest for processing?


 
0
isarana
Asked:
isarana
  • 2
  • 2
1 Solution
 
oleberCommented:
try

my $number1= "          -3.0000";
$number1 =~s/[ -]//g;
print $number1;
0
 
isaranaAuthor Commented:
oleber-
Thanks, that does the stripping and prints out 3.0000.....is there an easy way to add an open parentheses at the beginning and and close parenthesis at the end so it prints (3.0000)?  I'll give you the points either way...
0
 
oleberCommented:
my $number1= "          -3.0000";
$number1 =~s/[ -]//g;
$number1 = "($number1)";
print $number1;
0
 
isaranaAuthor Commented:
Thanks, I should have got that last part, I think I'm brain dead....
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now