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

Split String, Delete to the Left of the Splitter

Status
Not open for further replies.

MarkB1000

Technical User
May 14, 2007
4
US
I have strings in a database field {User} of variying lengths from 15 to 40 characters. These strings have user names listed in the following convention: userGroup/Function/UserName. Any one of these labels may be from 2 to 20 characters. I need to isolate the UserName and group by it in a crosstab. Somehow, I will have to count from the right to the first "/" and delete the remainder of the string to its left. I think I need a for-loop, but am not sure how to write it in Crystal Reports (using Version 11.0).

Any help would be great!.

Thanks.
 
Hi,
If it is ALWAYS 3 sections then try:
@GetName
Code:
Stringvar Array UserField := Split({Table.User},"/");
UserField[3]

Use this formula in your Xtab



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
TurkBear,

Thank you for the response. I tried it. Unfortunately it is giving me the following error: "A subscript must be between 1 and the size of the array" and the Userfield[3] is highlighted. Sounds like the problem is the name string will be varying sizes. Does not there need to be a loop that runs through to get the data string length? I will work on trying to make this work, but any further help would be great.

Thank you again.
 
You can use UBOUND to find the number of table elements. Base your logic on what you find.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 10 & 11.5 with Windows XP [yinyang]
 
Hi,
As Madawc noted, if there are not at least 3 segments ( with 2 '/' s or more) then UserField[3] would give that error.

If the UserName is ALWAYS the last element, then try:
@GetName
Code:
Stringvar Array UserField := Split({Table.User},"/");
NumberVar LastPart := UBound(UserField);
UserField[LastPart]

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
I found one user in a list of 50 that does not have a "/" in the user name (user: BrakeOps). All others have the Group/station/username convention. I visually verified that.
I tried to use this:

If not(instr({Table.Field},"BrakeOps") = 1) then
Stringvar Array UserField := Split({Table.Field},"/");
NumberVar LastPart := UBound(UserField);
UserField[LastPart]
Else {Table.Field}

Still errors with the "A subscript must be between 1 and the size of the array". Any further help would be great.

Thanks.
 
Better to use UBOUND to get the number, then try different sorts of split on the basis of what UBOUND finds, 3 or 2 or 1

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 10 & 11.5 with Windows XP [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top