I have a Styled text area that have multiple paragraphs, each paragraph has it’s own style like: font, size and color.
When i do the code to replace some letters, after replace is done, all the paragraphs text are loosing it’s styles and becomes in one style as the first paragraph style!.
I use the following code:
Dim s As String
s = TextArea.text
s = Replaceall (s,"A","a")
TextArea.text = s
Yes i tried StyledText.Text property, but after the replacement done, all the text area has no style at all, a Black color text with no style and the default font size.
Another attempt then:
Copy the replacement text to a new Styledtext, append each style run from the original to the copy and then assign this to the StyledText property of the TextArea.
Thank you very much Alberto for your help. It works now just fine for all letters except for “Carriage Return”, I tried to replace all extra carriage returns in the text but no luck!, it does not work. I tried to replace: Chr(13), Chr(10), EndofLine.Windows, EndofLine.Macintosh and EndofLine.Unix… but neither of them works. I don’t know why all letters are replaceable but “Carriage Return” does not !!.
I’m using Mac OSX, and the text is generated on the Mac.
Mujahed, can you post your code? You said “replace all extra carriage returns” but English is not my first language, so I can interpret that as “have 2 or more” (next to each other) and want to replace all those to only 1 line end, but I’m not sure if this is what you want.
EDIT: if you are using RTFData, then you may not have “Carriage Return” but code for end of Paragraph \\par
Yes Alberto, I have 2 or more" (next to each other) and want to replace all those to only 1 line end after each paragraph. The above code you provided works very good for all letters, But it is not replace Carriage return. It seems it does not recognize it!!
As i said, the text is generated on mac, i used a normal Mac OS carriage return.
Mujahed, I edited my post, maybe you didn’t see the edit. I think you will need to use \par\par to \par as the ReplaceAll.
Note: some of my tests there is a space between the first \par and the second. So I did:
s = ReplaceAll (s, "\\par ", "\\par")
s = ReplaceAll (s, "\\par\\par", "\\par")
you need to change it to take care of 3 carriage returns and maybe other cases.