Losing Styled text after replaceall

  1. last week

    Hi all,,

    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

    Any help please!

    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.

  2. Ulrich B

    Jan 8 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    Did you try the replacements on the StyledText.Text property instead?

  3. Thank you Ulrich,

    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.

  4. Tim P

    Jan 8 Pre-Release Testers feedback://46303

    The TextArea.Text property is not styled. To get and set styled text with a TextArea you need to use the StyledText property.
    This is covered in the documentation: http://docs.xojo.com/TextArea

  5. Ulrich B

    Jan 8 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Mujahed K 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.

  6. Emile S

    Jan 8 Europe (France, Strasbourg)

    The reason why you loose text is because you programmed it to do that. The offending line is:

    s = TextArea.text // No style copied in s
    // then later:
    TextArea.text = s // No style to set back !

    Because s do not hold any style.

    You have to change the whole Replace code.

  7. Thank you all Tim, Ulrich and Emile.

    I will be very appreciate if you can provide a sample code.

  8. Alberto D

    Jan 8 Pre-Release Testers, Xojo Pro

    The following code will work if:

    • you use a mac
    • you copy/paste the paragraphs from Notes with color/font/style into the TextArea1

    so this may not be what you want.

    Dim s As String
    s = TextArea1.StyledText.RTFData
    s = ReplaceAll (s, "A", "a")
    TextArea1.StyledText.RTFData = s

    Are you setting the Style within Xojo?
    Are you bringing the style/color/font from another app?

  9. 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.

    Very appreciate your concern.

  10. Tim S

    Jan 8 Canterbury, UK

    @Mujahed K 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 !!.

    Try replaceLineEndings().

  11. Alberto D

    Jan 8 Pre-Release Testers, Xojo Pro
    Edited last week

    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

  12. 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.

    Regards

  13. Alberto D

    Jan 8 Pre-Release Testers, Xojo Pro Answer
    Edited last week

    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.

  14. Alberto D

    Jan 8 Pre-Release Testers, Xojo Pro

    You can do something like:

    Dim s As String
    s = TextArea1.StyledText.RTFData
    Break

    and see the Text and Binary contents of 's' to find if your string has End of Lines or \par

  15. Markus W

    Jan 8 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    @Alberto D;Poo The following code will work
    Dim s As String s = TextArea1.StyledText.RTFData s = ReplaceAll (s, "A", "a") TextArea1.StyledText.RTFData = s

    This only works in VERY restricted circumstances. Try replacing all “a” with “b” or all “a” with “something” and see what happens.

  16. Thank you so much Alberto for your help, I'm really very appreciate your concern. It works fine now.

    Thank you also Tim for your help.

    Have a great Day and a happy new Year :)

or Sign Up to reply!