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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting String 2

Status
Not open for further replies.

DrHabi

Technical User
Jan 22, 2002
103
US
I have a string I need to split up.


Sometimes it is it is like this: item1_item2 or item1_item2_item3_item4 or item1_item2_item3_item4_item5_item6_item7_item8

I need to get all the items but it is unknown if there is 0 or 8 items but always split with an _ .
thanks any help would ge great
 
Why not post what you intend to do with them after you "get them"?

Fornmulas such as the following will break them out individually:

whileprintingrecords;
stringvar array MyValues:=split({table.field},"_")
if ubound(MyValues) > 0 then
MyValues[1]

Incrementing the > 0 amount and the [1] for later values.

Or you can just display them all using somehting like:

join(split({table.field},"_"),chr(13))

Remember to select can grow for the formula above.

Now youprobably realize that your post asked a yes no question, rather than stating a requirement. Please identify what you need in the future, reports output things, not get things.

-k
 
What are you going to do with it once it's split up?

Use this kind of format for each element you want to display separately:

//{@element1}:
stringvar array x := split({table.string},"_");
numbervar i := ubound(x);
if i >= 1 then
x[1]

//{@element2}:
stringvar array x := split({table.string},"_");
numbervar i := ubound(x);
if i >= 2 then
x[2]

etc.

-LB
 
I have to create headers for items that run along the grouping. I will take this string and create formula to identify the items having activity in that location of the field. There is another table that has 8 locations and it is unknown what the items are until you parse this field apart.
this is the formula I was using but it was giving me errors
I did 8 different formula like this only adjusting the number as follows:

if {zetup08.bigstring}>'' then if instr({zetup08.bigstring},'_') = 1
then split({zetup08.possystem},'_')[1] else "item1" else "item1"

second :
if {zetup08.bigstring}>'' then if instr({zetup08.bigstring},'_') = 2
then split({zetup08.possystem},'_')[2] else "item2" else "item2"


I am trying out your formula and will let you know if they worked thanks for the responses and I know this should help.
 
Thanks for the help but just have one issue I haven't quite figured out. It seems that if there is ( in this example) just two item it will not print the item 3 default name but leave it blank and but will be fine for the rest 4,5,6,7,8
stringvar array x := split({zetup08.possystem},"_");
numbervar i := ubound(x);
if i >= 3 then
x[3] else
"item 3
 
Why are you creating a default? I just tried the formula you are showing here, and when there were only two items in the array, "item3" was printed. Is this what you want to happen?

Can your field be null? If so, then try:

stringvar array x;
if isnull({zetup08.possystem}) then
x := "" else
x := split({zetup08.possystem},"_");
numbervar i := ubound(x);
if i < 3 then
"Item3" else
x[3]

-LB
 
So your idea is to parse the values out and then join them to a subreport?

I'm guessing that's what "There is another table that has 8 locations and it is unknown what the items are until you parse this field apart." means...

Sounds inefficient if that's the case.

Did you know that you can probably parse it WHILE joining to the lookup table using SQL, and that you might be able to do so within a Command Object in Crystal?

Or you might create a view which permanently straightens this bad database design out.

I demonstrated this here about a year ago using Oracle, a solution I worked out by using the Oracle forum.

Take a look around at successful posts, they supply technical information, these blog-like posts, as we beg you to disclose details are time consuming.

Try posting:

Crystal version (post your version with any software posting)
Database/connectivity used
Example data (show what's being returnedto the report)
Expected output (show what and where you will display)

-k
 
thanks for the reponses. I have decided that it was not neccesary to put a default location name. I was using a item in the formula but these are really sublocations within a location. What the string is used for is the customer naming the sublocations ie:( top shelf; middle shelf; pantry as examples) so when they took inventory they posted a physical qty for all sublocations that posted in the sytem for an overall location (kitchen1). In this table we have a qty1,qty2,qty3,qty4....qty8 but it does not have any link back to the sublocation since it is just too many extra locations. This will be used to identify the sublocations the they use to match up their counts if they are issues but they are not "locations" within the application but only text info put into a text box to them to. thanks again and hope this clears up what I am using this for.
 
synapsevampire, I have tried your suggestion with a string I need to split.
My string contains: ProductName - Title
I need it to see only the ProductName, and nothing after "-" but, when I use the formula
whileprintingrecords;
stringvar array MyValues:=split({table.field},"-")
and check it, I get the error "The result of a fromula can not be an array"

I am using CR XI connected to an Oracle server.

Please provide suggestions for how to get this information. Thanks!
 
Try:

whileprintingrecords;
stringvar array MyValues:=split({table.field},"-");
MyValues[1]

You should start new posts.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top