Inserting String into another

Tyrael

Member
Joined
Aug 6, 2008
Messages
8
Programming Experience
Beginner
Hello everyone:) I'm new to the community, and I am quite a beginner, and I would like to ask how do I insert a string or word into another? (sorry for my bad English)

For example I got this:
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><embed src="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>

and I want to add the blue colored text into the position that its placed in.

<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1&fmt=18"></param><param name="allowFullScreen" value="false"></param><embed src="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1&fmt=18" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>

and how do I add &fmt=18 at the end of a link?
like:
from this : http://www.youtube.com/watch?v=PiQMAK1IBqA&feature=related

to this : http://www.youtube.com/watch?v=PiQMAK1IBqA&feature=related&fmt=18

This little thing I would like to make it work for my Web browser on my Youtube Embed Video Viewer that works by inserting and reading embed code + it opens the video in a new link. Thanking you.

I'm using VB.net 2008 Express Edition.
 
Something as simple as "replacing" the value may work for you:

VB.NET:
Dim myString as String = "<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><embed src="http://www.youtube.com/v/Ksov8yNt70k&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>"

myString=myString.Replace("en&fs=1","en&fs=1&fmt=18")

This will replace the first string "en&fs=1" with the second, which is really just the first string with the additional text.

Alternativly, you could catch the indexes of "en&fs=1" in the string and string.Insert after each one; though, from the simplicity angle, my first though seems easier to understand.

Let me know if it works!
 
I'm sorry

When I use the code you provided, it says that could not create an instance of object, and when I remove it, the project works.
 
Sorry, that was somewhat just pseudo code, it will not compile because of all the quotation marks in your string.

I am assuming that you have that long string already in a variable, which i referred to as "myString".

You should be able to take that variable that you have the information stored in, and do the replace as I showed:


myString=myString.Replace("en&fs=1","en&fs=1&fmt=18")


Does that portion work?
 
Well it seems that the problem is when I try : Dim myString as string = "<....the code comes here....>"
It says: An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object. Invalid Operation Exception Was Unhandeled.... :confused::confused::confused:

But how could I make something like :

My string = richtextbox1.text
and then replace....something like this...:|
 
Ah, ok, so you have that long string in a text box on the form then?

You should be able to add code to your button (or however you execute the code) that does the same thing:

VB.NET:
Dim myString as String = RichTextBox1.Text
myString = myString.Replace("en&fs=1","en&fs=1&fmt=18")

'Then do something with myString.
 
Wouldn't you just be able to append it to the end like so?

VB.NET:
My string = richtextbox1.text & "&fmt=18"
 
Wouldn't you just be able to append it to the end like so?

VB.NET:
My string = richtextbox1.text & "&fmt=18"

At least in the example given, no. Tyrael needed to insert the "&fmt=18" portion of the string at two locations within his original string, with neither being at the end.

I believe the find and replace I showed initially will remain his easiest, though perhaps not the most (memory) efficent option.
 
Thanks so much guys

Well thanks a lot guys:D :D well When I used this:
Dim TestString123 As String = RichTextBox1.Text
Dim aString123 As String = Replace(TestString123, "http://www.youtube.com/watch?v=", "http://www.youtube.com/v/")

Dim TestString As String = RichTextBox1.Text
Dim aString As String = Replace(TestString, "INSERT_MY_NEW_CODE", aString123)

It Worked !

Raven65 you're one of the real masters here, and Dgorka thanks for that tiny little script you gave me:D so helpfull:rolleyes:. Now I know where I did a mistake, thanks guys...Heres some rep for you:) you deserve it , both.


PS : I don't know how to give rep on this forum:* if you could tell me please:p:p LOL a noob like me.:)
 
Back
Top