Converting numeric substrings to numbers for calculations

Post Reply
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Converting numeric substrings to numbers for calculations

Post by barry.marcus »

I have a need to search for numeric portions of strings in my data, do a simple calculation on them, and reinsert the result back into the string forming a new string. I can't seem to get my head around how I would do it.

Specifically, supposing I had a string that looked like this:

<$inData="action/4 request/3 dimension/2">

How would I, say, double the "request" identifier and so that the resulting string is:

"action/4 request/6 dimension/2"

I don't necessarily want to always double values, but I'm just saying this as an example. Once I figure out how to extract the specific numeric piece and reinsert it back into the string, I can handle all the various calcs I need to do.

Thanks in advance
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Converting numeric substrings to numbers for calculations

Post by mark »

User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Converting numeric substrings to numbers for calculations

Post by mark »

use <capture><sb>$inData</sb></capture><$outData=$ret> to put into a string instead of print.
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Converting numeric substrings to numbers for calculations

Post by barry.marcus »

Thanks! This works great!
Post Reply