Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I need find a string inside a string and remove rest of the string.

my string will be 220,220,220,220
I need to remove only one 220 from above string format.

Any idea please.
Posted
Updated 7-Dec-15 22:16pm
v2
Comments
Snesh Prajapati 8-Dec-15 4:17am    
Is it resolved by the answer given by Mario ? or you want something else ?

1 solution

Try the following:
C#
string input = "my string will be 220,220,220,220";
string find = "220";

int searchIndex = input.IndexOf(find);
input = (searchIndex < 0) ? input : input.Remove(searchIndex, find.Length);

I've just noticed you tagged your question with VB.NET so here is the version for that language:
VB
Dim input = "my string will be 220,220,220,220"
Dim find = "220"

Dim searchIndex = input.IndexOf(find)
input = If((searchIndex < 0), input, input.Remove(searchIndex, find.Length))
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900