Remove part of a string


#1

Hello friends,
I need to manipulate the "Contraente " column so that it eliminates the part of the string “ProprietarioCATTANEO MARIKA SONIA” because it contains a repatition of the first part.
20180709.xlsx (22.7 KB)


How can I manipulate the string?
Thank you so much,
Camilla. :slight_smile:


#2

Hey @CamiCat

You can use String.Remove function!

Assuming you only want to change that particular cell , you could do something like this(assuming str is holding the value at specified cell)

str = str.Remove(str.IndexOf(“Proprietario”))

If you are iterating through the whole DataTable you can check
if row(“Contraente”).ToString.Contains(“Proprietario”)
then row(“Contraente”)=row(“Contraente”).ToString.Remove(row(“Contraente”).ToString.IndexOf(“Proprietario”))

Hope this helps :slight_smile:

Cheers!


#3

Thank you so much @Rishabh_Lakhera.
I’ll try with your suggestion and let you know as soon as possible.
Camilla :slight_smile:


#4

Unfortunately I tried your solution but it doesn’t work.
have you kindly got any other ideas?
Thank you so much,
Camilla :slight_smile:


#5

Are you getting an error? Or an unchanged string? Because i tried the same on a test string and it worked fine!


#6

Hi @CamiCat,
I have done the sample for this situation.

File : RemovePartOfAString.zip (18.4 KB)

Regards
Balamurugan.S


#7

Thank you so much @balupad14.
Your solution is very good.
Camilla :slight_smile:


#8

Hi Guys,

I’m having slightly similar problem. I tried the method but it can’t work.


Regards,
Bhaarathan


#9

Hi @Bhaarathan,

Can you explain your situation ?

Regards
Balamurugan.S


#10

Hi Balamurugan,

What i’m trying to do is that, I want to remove any characters after the space.
For example,
String id = “HDB000ETT18300105 / DPG-TN180009”
I want to remove anything that is beyond the space character
So my output must be id = “HDB000ETT18300105”
I tried using the method of id=id.Substring(0,strWord.IndexOf(" ")).Trim
but it did not work for me.

It needs to loop through all the rows to check and remove the unwanted characters.

Can you help me please?
Thank you.

Regards,
Bhaarathan


#11

Hi @balupad14,

I managed to solve the problem.
I just needed to add an condition to check whether there is any space in the String of characters.

Thank you anyways for guiding me.

Regards,
Bhaarathan


#12