Removing part of a string
I have a bunch of strings that have to have lines removed from them. I know the beginning and end words of each line, but I don't know what may be in between them.
Is there any way in VB2005 to search through each string and look for the beginning marker and the end marker of the text that needs to be removed and then delete that and everything in between?
Re: Removing part of a string
Why not just do:
strVariable = strVariable.Replace(Environment.NewLine, "")
Re: Removing part of a string
MetalKid, he wasn't real clear, but im not sure if the lines he is looking to remove are actually BLANK lines, or lines with text in them.
Re: Removing part of a string
The lines that need to be removed are actually xml tags of text. So I know what the beginning and end of the tag will be, I just don't know what will be in between. I guess that's where the problem is. I've seen the string replace function, but I thought you could only use that if you knew exactly what you wanted to replace.
Re: Removing part of a string
Probably wants the latter. Probably using a mixture of the IndexOf and Substring methods would work to get what you want or regular expressions if you are feeling up to it.
EDIT: I think XML has something about InnerText and OuterText and getting them. Search the forum for something like that. Someone complained the other day that all they did was post the solution to a problem like this.
You should have mentioned XML in post 1. Better description of problem = quicker/better solutions
Re: Removing part of a string
if the entire document is an XML document you should use the classes in the XML namespace like the XMLDocument class to load the XML file.
The XML classes have an extensive library of functions for adding/removing/editing the XML nodes in the document, and when you are done, you simply call the save method and save the file back to disk.
Sure you could do it with a bunch of messy string manipulation, but why bother when you could code it way cleaner, and learn all about the XML classes in the process.