Add text before XX text?

Getox

Centurion
Joined
Jul 8, 2004
Messages
122
OK, I have a Rich Textbox now if i had say this code in it:

Code:
<html>
<head>
<title></title>
</head>
<body>


</body>
</html>

Now, i have a button that will add:
Code:
<style>

</style>

But that goes at the bottom of the page, How would i get it to add this before the </head> tag?
 
What code are you using to add this? If you are implementing a text editor then you will probably find the TextBox / RichTextBox controls will start to get a bit cumbersome as a way to do both store and edit the text.
You may want to look at some alternate storage ideas (arrays, lists etc) and only use the controls to display / edit the string.
Clicky is probably worth a read as it does give some good explanations of various possible approaches.
 
Well, i aint coded that part yet, but if i was to code it, i would just do a codebox.appendtext = "<style> </style>"

....Anyone know how to do a multiline one?
as
codebox.appendtext = "this
wont work"
 
If you want to put the text before the "</head>" tag why would you be looking for an append function?

Just because I'm a nice guy I'll give you this one :) ;) :

Dim sText As String = "<style>" & Environment.NewLine & Environment.NewLine & "</style>"

RichTextBox1.Text = RichTextBox1.Text.Insert(RichTextBox1.Text.IndexOf("</head>"), sText)
 
Ok, i got a problem, if the text "</head>" isnt in the textbox it crashes the app, how would i stop it from doing that?
 
Move the part:

RichTextBox1.Text.IndexOf("</head>")

before the insert, storing the return value in a variable. Check the variable - if it's -1 don't do the insert.
 
Machaira said:
Move the part:

RichTextBox1.Text.IndexOf("</head>")

before the insert, storing the return value in a variable. Check the variable - if it's -1 don't do the insert.
Little help with that please, What exacly do i do?
 
The IndexOf function returns a number which tells you the location of the string passed to the function in the text that's searched, in this case the text in the RichTextBox. If that number is -1 the string isn't in the text so you don't want to do the insert.

Surely you can modify the code on your own. If you want someone to do your coding for you, try www.rentacoder.com. ;)
 
Back
Top