Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Split formula in Text field Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: Split formula in Text field
     Posted: 23 Jan 2015 at 7:12am
I have a column with text that I would like to separate:
 
A~B~C~D~E
A~B~C~~E
 
I am interested in the text in B,C and E.
Sometimes, the text in position 4 will be Null.
 
stringvar myString := CStr({EpisodeTestComments.Text});
 
StringVar Array MyArray := Split(myString,"~");
StringVar MyA := MyArray[1] ;
StringVar MyB := MyArray[2] ;
StringVar MyC := MyArray[3];
StringVar MyD := MyArray[4];
StringVar MyE := MyArray[5];
 
MyB;
 
I get an error saying: "A subscript must be between 1 and the size of the array"
 
 
 
 
 
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 26 Jan 2015 at 10:23am
Try this:

stringvar myString := CStr({EpisodeTestComments.Text});
StringVar Array MyArray := Split(myString,"~");


StringVar MyA := MyArray[1] ;
StringVar MyB := MyArray[2] ;
StringVar MyC := MyArray[3];
StringVar MyD := "";
StringVar MyE := "";
if ubound(MyArray) = 4 then
MyE := MyArray[4];
else
(
MyD := MyArray[4];
MyE := MyArray[5];
)

-Dell
IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 29 Jan 2015 at 7:34am
The formula gave me an error. So in order to grab whatever is in position 5, I reversed the order of the string and grabbed whatever is in position 1:
 
If {EpisodeTestComments.Text} startswith"S~" then
(
stringvar myString := StrReverse(CStr({EpisodeTestComments.Text}));
StringVar Array MyArray := Split(myString,"~");
StringVar MyA := MyArray[1] ;
MyA;
)
else {EpisodeTestComments.Text}
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