|
-
Feb 11th, 2008, 03:41 PM
#1
Thread Starter
Lively Member
[2005] Why? (Replace text problem)
I am making/remaking a mail program i wrote quite some time ago.
It directly inserted HTML on the place it was needed what made quite a mess inside the textbox.
Now i wanna do this afterwards to replace things like [-B] TEXT [-/B] with html code so it wont mess up my text.
How ever i wanna do this with 'enters' too but that is where the problem starts.
If i put this code on the keyPressed event then it works all fine(remember Keys.ENTER is equel to 13(enum code)):
Code:
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
Console.WriteLine("enterpressed")
End If
It shows inside the output when i press enter.
BUT BUT BUT when i try to search to those 'enters' i just cant find them.
This is the code i have:
Code:
For Each s As Char In txtRich.Text.ToCharArray
If s = ChrW(Keys.Enter) Then
Console.WriteLine("Enter found")
End If
Next
it just dont find it.
And i have no idea why :S.
I made it work with comparing the hashcode(after printing the hashcode of the enter char to the output and copy it) but with that cant preform replacements in a string like this:
Code:
contentToSend = txtRich.Text.Replace(ChrW(13), "<br>")
Wich obviously dont work either.
(on all code samples i tried the normal chr(13) too.)
I hope someone can come with a solution and maybe wanna tell why i cant do this .
Greets
-
Feb 11th, 2008, 03:44 PM
#2
Re: [2005] Why? (Replace text problem)
You can't search for a Keyboard key as a character. Look for Environment.NewLine instead.
-
Feb 11th, 2008, 03:54 PM
#3
Thread Starter
Lively Member
Re: [2005] Why? (Replace text problem)
I tried :
vb Code:
txtRich.Text.Replace(Environment.NewLine, "<br>")
wich still doenst work.
Greets
PS i work with a rich textbox but i guess this should not make a difference to the .text property
-
Feb 11th, 2008, 04:03 PM
#4
Frenzied Member
Re: [2005] Why? (Replace text problem)
Try searching for vbNewLine instead of "<br>"
-
Feb 11th, 2008, 04:06 PM
#5
Thread Starter
Lively Member
Re: [2005] Why? (Replace text problem)
I wasnt looking for "<br>" but replacing with.
vbNewLine doenst work either when i place it on the same place as Environment.NewLine.
Greets
-
Feb 11th, 2008, 04:24 PM
#6
Frenzied Member
Re: [2005] Why? (Replace text problem)
Why don't you use Strings.Replace$?
-
Feb 11th, 2008, 05:13 PM
#7
Thread Starter
Lively Member
Re: [2005] Why? (Replace text problem)
I am useing that.
the property .text is a string
Greets
-
Feb 12th, 2008, 12:02 AM
#8
Re: [2005] Why? (Replace text problem)
Environment.NewLine is a String that contains a standard line break for the current enviroment. On a Windows system that is a carriage return ('\r', Chr(13), ControlChars.Cr) and a line feed ('\n', Chr(10), ControlChars.Lf). If your text doesn't contain those characters then your replacement won't work. These days Windows also understands just line feeds on their own, which is the standard line break on Unix-based systems. Have you checked what your text actually contains? If Environment.NewLine isn't working then it's likely that your text contains Unix line breaks, so try replacing ControlChars.Lf instead.
Also, it would be more correct to replace with the XHTML-compliant "<br />".
-
Feb 12th, 2008, 06:17 AM
#9
Thread Starter
Lively Member
Re: [2005] Why? (Replace text problem)
Thnx jmcil ControlChars.Lf (or chrw(10)) works .
Ty
Greets
-
Feb 12th, 2008, 06:19 AM
#10
Re: [2005] Why? (Replace text problem)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|