Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Formula for parsing a LONG string Post Reply Post New Topic
Author Message
doctork11
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: United States
Online Status: Offline
Posts: 5
Quote doctork11 Replybullet Topic: Formula for parsing a LONG string
     Posted: 24 Jan 2014 at 7:09am
Okay, I have a note entered by users into a SQL database. That note contains several entries. In the database (via the UI), they enter the note similar to this:

Value 1 [<_>] Value 2 [<_>] Value 3 [<_>]

The Value 1, Value 2, & Value 3 never change. Everywhere you find <_> in the note template, the user replaces that with their entry. The note text replaced is never the same length. It varies from customer to customer. So in real life (or something to that effect), it looks like this:

Value 1 [note text goes here] Value 2 [note text goes here for value 2] Value 3 [note text goes here for val three]

I wrote the following formula to capture the first part of the string.

Formula Name: fmtValue1
Left({Command.NOTE_TEXT},InStrRev({Command.NOTE_TEXT},"]")-1)

Now, what I need help with is the rest of the string. I need each Value selected as it's own formula. Something like(pseudo):

fmtValue1 then fmtValue2 where string starts after fmtValue1's value then fmtValue3 where string starts after fmtValue2 values, etc.

I was thinking of a count, but I can't quite get my head around it. Something like: count the number of characters in fmtValue1 then start fmtValue2 where the string > len(fmtValue1) but not past "]" then start fmtValue3 where the string > len(fmtValue2) but not past "]", etc...

Thank you for any assistance.
IP IP Logged
doctork11
Newbie
Newbie
Avatar

Joined: 29 Jul 2013
Location: United States
Online Status: Offline
Posts: 5
Quote doctork11 Replybullet Posted: 24 Jan 2014 at 7:55am
Well, after many failed attempts, I figured it out. Instead of making a mess of my formula, I simply used a split function with array...

fmtValue1 = split({Command.NOTE_TEXT},"]")[1] + "]"
fmtValue2 = split({Command.NOTE_TEXT},"]")[2] + "]"
fmtValue3 = split({Command.NOTE_TEXT},"]")[3] + "]"

[IMG]smileys/smiley32.gif" align="middle" />

Edited by doctork11 - 24 Jan 2014 at 7:55am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 29 Jan 2014 at 5:04am
looking at the solution, you could do this as well...
local stringvar array arr:=split({command.Note_text}, "]");
fmtValue1 = arr[1] + "]";
etc.

I try not to make anything work harder than it needs to...and constantly splitting would seem to slow the report down...at least it makes sense.

maybe for next time, just a thought
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum