Removing Certain Text from a Multiline Textbox

tonycrew

Well-known member
Joined
Apr 20, 2009
Messages
55
Programming Experience
Beginner
Hello, I have this..

VB.NET:
TextBox7.Text = TextBox7.Text.Remove("<game name=" & TextBox9.Text & ComboBox1.Text & TextBox9.Text & ">")

And what i am doing here is removing a peice of text from my multiline textbox (textbox7), But its not working..?

Can you help?

It comes up with an error saying..

VB.NET:
Conversion from string "<game name="6-Pak (USA)">" to type 'Integer' is not valid.
 
That's because you didnt read the Help.

VB.NET:
Public Function Remove(ByVal startIndex As Integer) As String
Member of: System.String

Summary:
Deletes all the characters from this string beginning at a specified position and continuing through the last position.

Parameters:
[B]startIndex: The position to begin deleting characters.[/B]

Return Values:
A new System.String object that is equivalent to this string less the removed characters.

Exceptions:
System.ArgumentOutOfRangeException: startIndex is less than zero.-or- startIndex specifies a position that is not within this string.

Your quickest solution would be to do :-

VB.NET:
TextBox7.Text = TextBox7.Text.Replace("<game name=" & TextBox9.Text & ComboBox1.Text & TextBox9.Text & ">", "")
 
Here's what parameters the Remove() method takes: String.Remove Method (System)

You're passing a string, when it's requiring an integer, which explains the invalid cast exception.

In your case I can just flat out tell you to change Remove() with Replace() and the 2nd string parameter you want is String.Empty:
VB.NET:
TextBox7.Text = TextBox7.Text.Remove("<game name=" & TextBox9.Text & ComboBox1.Text & TextBox9.Text & ">", String.Empty)
 
wait i goty somet wrong, is in the textbox i have multiple, here

VB.NET:
	<game name="3 Ninjas Kick Back (USA)">
		<description>3 Ninjas Kick Back</description>
		<crc>e5a24999</crc>
		<manufacturer>Malibu</manufacturer>
		<year>1994</year>
		<genre>Action/Platformer</genre>
	</game>
	<game name="6-Pak (USA)">
		<description>6-Pak</description>
		<crc>1a6f45dc</crc>
		<manufacturer>Sega</manufacturer>
		<year>1996</year>
		<genre>Miscellaneous/Compilation</genre>
	</game>

as you can see i have multiple games, and say when i press the button which empty's out the replacement.. it deletes/replaces all the ones that hhhave the same, etc

VB.NET:
	<game name="3 Ninjas Kick Back (USA)">
		<description>3 Ninjas Kick Back</description>
		<crc>e5a24999</crc>
		<manufacturer>Malibu</manufacturer>
		<year>1994</year>
		<genre>Action/Platformer</genre>
	</game>
	<game name="6-Pak (USA)">
		<description>6-Pak</description>
		<crc>1a6f45dc</crc>
		<manufacturer>Sega</manufacturer>

		<genre>Miscellaneous/Compilation</genre>
	</game>
	<game name="688 Attack Sub (USA, Europe)">
		<description>688 Attack Sub</description>
		<crc>f2c58bf7</crc>

		<year>1991</year>
		<genre>Simulation/Submarine</genre>
	</game>
	<game name="AAAHH!!! Real Monsters (USA, Europe)">
		<description>AAAHH!!! Real Monsters</description>
		<crc>fdc80bfc</crc>
		<manufacturer>Realtime Associates</manufacturer>
		<year>1995</year>
		<genre>Action/Platformer</genre>
	</game>
	<game name="Action 52 (USA) (Unl)">
		<description>Action 52</description>
		<crc>29ff58ae</crc>

		<year>1993</year>
		<genre>Miscellaneous/Compilation</genre>
	</game>
	<game name="Addams Family Values (Europe) (En,Fr,De)">
		<description>Addams Family Values</description>
		<crc>b906b992</crc>
		<manufacturer>Ocean</manufacturer>

		<genre>Role-Playing/General</genre>
	</game>
 
Sorry i havent sorted it it still removes all the items with the same text...? instead of just removing that one set.

VB.NET:
<game name="3 Ninjas Kick Back (USA)">
		<description>3 Ninjas Kick Back</description>
		<crc>e5a24999</crc>
		<manufacturer>Malibu</manufacturer>
		<year>1994</year>
		<genre>Action/Platformer</genre>
	</game>

So say i want to remove onlly this set of info it removes all info with the same year, same manufacturer etc..
 
Last edited:
Back
Top