Remove text from string after character

If i have text in a string e.g. “Text1 - Text2” how do i specify i want to remove all text after the "-"so that i am just left with “Text 1”?

1 Like

Why not buddy @jon1302 you can get all the text before - rather to remove after -

if we have like this text_variable = “Text1 - Text2”
then we can get with assign activity like this

text_variable = text_variable.Split("-" c )(0).ToString.Trim

this would give you all the text that are before -
we wont have any words after -

Cheers buddy

6 Likes

Did that work buddy @jon1302

Cheers

1 Like

Hello

I get an error: "Compiler error(s) encountered processing expression “stSupplierTitle2.Split(” - “)(0).ToString”. Option Strict On disallows implict conversions from ‘String’ to ‘Char’.

1 Like

Put like this buddy @jon1302

ext_variable = text_variable.Split("-"c)(0).ToString.Trim

2 Likes

Now buddy…!

1 Like

Awesome, working now :smiley: thank you!!

Cheers buddy

Keep going

1 Like

I modified so it is as follows: stSupplierTitle2.Split("-"c)(0).ToString

Though if i try to change “-” to " - " i get a message that the character constant can be only one character. Is there a way to make it work for more than one character?

3

Buddy the reason is T/A is not a character as character is a single word while - is a single character that should be actually mentioned in single quote. As we were mentioning that - in double quotes, we need to declare explicity as character. So we mentioned as "-"c

Here “T/A” is not a character, so remove that c nextto "T/A"c and just write as “T/A”

That would work buddy

Cheers

1 Like

Thanks, i tried but giving a similar error to before:

4

Or try like this buddy

Split(stSupplierTitle2,“T/A”)(0).ToString.Trim

and may i know what is there before T/A buddy

2 Likes

Before T/A will be a company name e.g. DOT MANC LTD T/A FLORAL IMAGE MANCHESTER. So there will always be a space just before T/A. I tried the above but showing the following now:

THIS ONE IS WORKING BUDDY
Split(kout_string,“T/A”)(0).ToString.Trim

2 Likes

Not sure if i entered correctly:

remove that strSupplierTitle2 before split
and start with split alone buddy

1 Like

I remove the kout and left with Split(stSupplierTitle,“T/A”)(0).ToString.Trim

Working now! Thank you so much for your help as always. You are awesome!

1 Like

Cheers buddy

Keep going :wink:

@Palaniyappan

I have a follow up question. In the above example the T/A is removed and all text after it. Would it be possible to modify so that T/A remains but all the text after is removed so e.g. “Text 1 T./A Text 2” becomes “Text 1 T/A”?

you can concatenate the text that you have taken as delimiters in split method buddy