Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing substrings 1

Status
Not open for further replies.

martinjt

Technical User
Aug 1, 2008
34
US
I'm using Crystal9 with Oracle Server. I'm having trouble extracting substrings from a string that is a result of a variable formula. I have two numbers that are being used and converted to text, the timekey (x) and the number recorded with that key (n).

I'm using this approach because I need to allow for identical n values (n1 could equal n2).

Here is the accum formula:
WhilePrintingRecords;
StringVar keynumber;
If Instr (keynumber,totext({RECORD.KEY})) = 0 then
keynumber := keynumber + totext({RECORD.KEY}) + "|" + totext({RECORD.NUMBER}) + ", ";

Example result:
x1|n1, x2|n2, x3|n3

What I need to show is just the n values separated by ", " like this:
n1, n2, n3

How do I remove x1| and x2|, etc and still keep n1, n2 etc?

Any ideas?
 
martinjt,

If I understand your post, correctly I think you could change your code to as follows to achieve the desired results. Unfortunately, I am unable to test this to be sure, but I am thinking it could be a quick test for yourself.

{@AccumFormula}
Code:
WhilePrintingRecords;
StringVar keynumber;
If Instr (keynumber,totext({RECORD.KEY})) = 0 then
[red]keynumber := keynumber + totext({RECORD.NUMBER}) + ", ";[/red]

I beleive this should prevent the "x" values from ever being added into the string. Please advise as to your findings.

Hope this helps, Cheers!



Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
The problem with that is that the key isn't being accumulated in the variable which will only contain the number. It needs to accumulate to make sure the record is used only once in the string.
 
Thanks MartinJT,

I wondered if there might be a reason that route wasn't taken. Makes perfect sense.

Unfortunately I am not all that well versed in Array's, but from looking at your post I would think that if you could "break" the string on the "|" into an array, you could most likely loop through the array and remove the necessary characters. That being said, it is only an idea as I have not worked with array's personally, it just appears to be something that looks like it could be an array.

Hopefully another Tek-Tipper will be able to shine some light on a solution for you.

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
That's exactly right! I was mulling around in my head how to do it and I finally got it. I used a combination of formulas to split the string into pieces, then I combined the results into the exact string I needed. Here's an example of one of them:

If Length ({@SHOWFORMULA}) = 0 then
""
Else
If InStr ({@SHOWFORMULA},"|") = 0 then
""
Else
If Ubound(Split({@SHOWFORMULA},"|")) > 2 then
Split({@SHOWFORMULA},"|")[3]
 
MartinJT,

That's Great!! Glad to hear you found a solution!

Just curious, if you don't mind my asking. It just now crossed my mind that perhaps simply copying your original formula and making my previously-posted change in the new copy -- would you have been able to use the new formula for display/formatting and your original formula could still be used for it's original purpose -- or would the formula's conflict?

Thanks for sharing your solution with us, it is always appreciated.

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
I'm not sure I understand your question but copying is copying whether from subject text or the new copy (code?)area. They both work. I don't like the codes that show on one row however and you must scroll to see it. It is much better to utilize them the way you posted above. Thanks for your help! It's great to have a soundboard for these ideas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top