×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

some questions about manipulating a $

some questions about manipulating a $

some questions about manipulating a $

(OP)
I have some questions about manipulating the contents of a $:

- I’m trying to standardize the look of a nummeric variable field.

The input can be for example:

1000000
1.000.000
1,000,000

they all should finally look like:

1.000.000

I can only think of getting  the length of the string and  use substring to clear potential dots etc. then reverse the string and insert dots after every 3 digits and reverse it again but probably this is much easier done in Perl?

- What is the quickest way to clear all characters except the digits from a string?

- Let’s say you have a datafile with a nummer of fields seperated by “:”.  You don’t want to store a new record to this file with a variable with “:” in it as it will mess up the record when reading it from the datafile. What is the fastest way to check all fields for “:” and replace it with for example “;” before saving it?

Raoul

RE: some questions about manipulating a $

' sounds to me like you need a little regex replacement stuff......


$str = '10,000,000';
$str =~ s/\D//g; # replace all non-digits with null



Second item,

$str = 'some text with : colons embedded : ';
$str =~ s/:/\;/g; # replace all ':'s with ';'s.  
              # Must escape ';' to keep Perl from
              # ending statement on ';'.



'hope this helps.




keep the rudder amid ship and beware the odd typo

RE: some questions about manipulating a $

Hai!

I hope this too help you .

$number=1000000;
$number= reverse($number);
$number=~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
$number=reverse($number);
print $number;



RE: some questions about manipulating a $

(OP)
Thanks both. Works great!

Does anybody knows a good site for more info about this sort of stuff. I checked some documentation but what I found was totally not useful.

I would like to get more info about this for doing a search through a data file with fields that match a certain number of characters and that sort of stuff.

Raoul

RE: some questions about manipulating a $

At www.perl.com, via their search, choosing 'regular expressions' from the pull down, you get this list of resources.....

http://www.perl.com/reference/query.cgi?section=regexp&x=11&y=14

The last link on that page, 'Regular Expressions', is a pdf of a chapter from a book that does a pretty good job.

Additionally, if you have some specific regex problem, feel free to post it.  I'm sure some one will find one of the 'more than one ways to do it'.

'hope this helps.




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close