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

Replace using a wildcard and for a certain length

Status
Not open for further replies.

terrym777

Technical User
Jun 14, 2010
31
0
0
US
I am having difficulty trying to strip out a variable length string at the end of a title text field. There are 4 different cases and they may be a different length. For example,

Yoga Class - Spring
Yoga Class - Summer
Yoga Class - Fall
Yoga Class - Winter

I want my output to just be Yoga Class.

Here is a sample of how it works if I hardcode one of the cases.

Replace(Title;" - Spring","",1,-1,1)

I cannot replace Spring here with a wildcard, such as "*".
Do I have to do this using Boolean logic for all 4 cases?

Thanks for your help.
 
If ubound(split({table.string},"-")) > 1 then
trim(split({table.string},"-")[1]) else
{table.string}

-LB
 
TerryM777,

A formula as follows should give you the result you seek:
Code:
Left({Table.Title},Instr({Table.Title}," - "))

Hope this helps!

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."
 
Thanks LBass! (i clearly took too long typing this one)

And yes still missed a key part... my post shoud have read:
Code:
Left({Table.Title},Instr({Table.Title}," - ")[b]-1[/b])

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."
 
Thanks to both of you for your help however I got the same error message on both "The remaining text does not appear to be part of the formula". In both cases, it was the last parenthesis that was hilited. Here is how I ended up getting it to work the long way. I had to program it to also take into consideration that there may not be a space after the "-" in the title. It still would be nice if I could get it to work with one of your suggestions. In any case, thanks again for your help!

If {SESSION.Title} like "*- spring" Then
Replace({SESSION.Title}, "- Spring","",1,-1,1)
Else
If {SESSION.Title} like "*-spring" Then
Replace({SESSION.Title}, "-Spring","",1,-1,1)
Else
If {SESSION.Title} like "*- summer" Then
Replace({SESSION.Title}, "- Summer","",1,-1,1)
Else
If {SESSION.Title} like "*-summer" Then
Replace({SESSION.Title}, "-Summer","",1,-1,1)
Else
If {SESSION.Title} like "*- Fall" Then
Replace({SESSION.Title}, "- Fall","",1,-1,1)
Else
If {SESSION.Title} like "*-fall" Then
Replace({SESSION.Title}, "-Fall","",1,-1,1)
Else
If {SESSION.Title} like "*- winter" Then
Replace({SESSION.Title}, "- Winter","",1,-1,1)
Else
If {SESSION.Title} like "*-winter" Then
Replace({SESSION.Title}, "-Winter","",1,-1,1)
 
lbass' solution should have worked like a charm.

if you still have the erroring formula, copy-paste it and we can try to help find the problem.

while your approach will work, it is the brute force method.

Also, if there is any chance there could be null values, you would want to add logic for that at the very top of your formula, something like this: IF isnull({SESSION.Title}) or TRIM({SESSION.Title})="" then " " ELSE //.....<rest of your formula here>
 
Please show exactly how you implemented my suggestion.

-LB
 
If Ubound(Split({SESSION.Title},"-")) > 1 Then
Trim(Split({SESSION.Title}),"-")[1])
Else
{SESSION.Title}
 
Hi lbass,

I just found my typo in your formula! Thanks for the help again.

Terry
 
Thanks also to you too Mike. I had the same typo in your formula and it worked also. And thank you too Fisheromacse for your suggestion.
 
For other readers:

If Ubound(Split({SESSION.Title},"-")) > 1 Then
Trim(Split({SESSION.Title},"-")[1]) Else
{SESSION.Title}

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top