Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I want to delete or remove a part of a string?
I need to write a method or do something which will read the str1 and str2. when it finds the str2, it will delete it from str1 and update the str1.

To be more clear,

Lets say I have:

string str1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."

string str2 = "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, "

The final string should be;

str1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. when an unknown printer took a galley of type and scrambled it to make a type specimen book."";

I cant use substring method because str2 can change because of the input string.
Posted
Updated 16-Nov-10 8:27am
v2

1 solution

try:
str1 = str1.Replace(str2, "");
http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^]

[edit]Don't need the declaration of str1 as a string... Doh![/edit]
 
Share this answer
 
v2
Comments
Orcun Iyigun 16-Nov-10 14:53pm    
thanks for the fast reply..

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