How to remove the end of a string in a variable

Hello and thank you for any help. I have a variable called strReqType that pulls a string from a website. As a variable, each time I pull the variable the contents are different
Examples:
Claims - claims handling
Complaint - driver issue
Service request - send copies
Customs inquiry - customs process
etc

What I want to remove in the variable is the last space before the dash and the dash and everything after it. I have about 25 of the first half of the variable and dozens of the second half. How can I accomplish this task?

Thank you

1 Like

Assign strReqType to strReqType.tostring.split("-"c)(0).Trim

1 Like

@Mr_Meeseeks - Thank you, I want to remove also the space before the dash so should it be
Assign strReqType to strReqType.tostring.split(" -"c)(0).Trim
?

Thank you

1 Like

Hi buddy
This expression would remove all next to the first word (as your described)
Split(Str_input,ā€-ā€œ)(0).Trim

Here Trim is used to remove the blank spaces in front and back of the word and split does the splitting with delimiter

Hope this would help you
Cheers @mworth123

1 Like

@mworth123 both of them should work

1 Like

@Palaniyappan - Thank you, In several cases I have more than one word to the left of the hyphen. Iā€™m not sure how your code would keep the right parts. I want to delete everything to the right of the hyphen and also delete the space before the hyphen

yah sure it would
let me tell you how it works
so our expression is
Split(Str_input,ā€-ā€œ)(0).Trim

and the input is if
Str_input = Claims - claims handling
then the above expression will split like this

input : Claims - claims handling
splitting : Claims |-| claims handling
0 (our delimiter -) 1
where
0 = Claims* (* is the space)
delimiter = -
1 = claims handling ( is the space)

i have used pipeline symbol for how it would work if we have one word before to that -
and TRIM method will remove those spaces i.e, the place where * is mentioned

and if we have more than one word or even a sentence before -
like this
input : Customs inquiry |-| customs process
splitting : 0 (out delimiter -) 1

where
0 = Customs inquiry*
delimiter = -
1 = *customs process

so whatever that comes before - will get splitted with this expression and as we have mentioned only 0 in the expression it will give us only the value before to the delimiter 0

hope this would helpyou
Cheers @mworth123

@Palaniyappan - Thank you for the explanation. As long as your piece of code removes the space before the hyphen and the hyphen and everything afterwards I should be good. The reason this matters is because next I will use a series of IF statements to search for the first half of the string strReqType and if the space is there it will fail.

I am on vacation until 10/28 and I will insert your idea into my process and see what happens. Thank you!

Cheers @mworth123

Enjoy your vacation
See you soon @mworth123