Text file with RichStringFormatter?

enonod

Well-Known Member
Licensed User
Longtime User
I have been struggling with the newly found RichString Library.
I have rightly or wrongly made the assumption that in the middle of a text file I can embed a token that I have prepared in Initialize.
My problem is that all the examples seem to be short hand prepared text on a label.
I am using a text file to a label in a ScrollView, but cannot see how to pass the text 'through' whatever in order for the text to arrive on the label, formatted.
I have TextRead the long file to a standard string but cannot see the next step.
Will a knowledgeable person please help.
 

agraham

Expert
Licensed User
Longtime User
The text string should have the embedded formatting sequences that are whatever you have defined them. They are free form but the start and end characters must not otherwise appear in the text.
B4X:
' initialise a RichString with your text
Dim rs As RichString
rs.Initialize(myString)

' initialise a RichStringFormatter with a sample token, only the fist and last characters are significant
Dim rsf As RichStringFormatter 
rs.Initialize("{example}")

'define your formatting tokens
rsf.AddToken("{R}", rsf.FORMAT_RELATIVESIZE, 1.5)
rsf.AddToken("{T}", rsf.FORMAT_TYPEFACE, "serif")
rsf.AddToken("{Blue}", rsf.FORMAT_COLOR, Colors.Blue)
rsf.AddToken("{Red}", rsf.FORMAT_COLOR, Colors.Red)
rsf.AddToken("{U}", rsf.FORMAT_UNDERSCORE, Null)
rsf.AddToken("{BI}", rsf.FORMAT_STYLE, rsf.STYLE_BOLD_ITALIC)

' format the RichString using the RichStringFormatter and assign it to your label
rs = rsf.Format(rs)
MyLabel.Text = rs
It's all shown in the demo.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you. Yes I did use the example but fed the text I read from a file and received this error, which I confess I do not understand.
Compiling generated Java code. Error
B4A line: 718
lines=rsf.format(lines)
javac 1.6.0_26
src\b4a\example\main.java:1374: inconvertible types
found : java.lang.String
required: android.text.SpannableString
_lines = String.valueOf(_rsf.Format((android.text.SpannableString)(_lines)));Debug.locals.put("lines", _lines);
from
B4X:
Reader.Initialize(File.OpenInput(File.DirAssets,"Text.txt"))
   lines=Reader.ReadAll
   Reader.Close

   lines=rsf.format(lines)
   lblText.Text=lines
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Yes I did define everything elsewhere and assumed correctly that it did not cause the problem.
Thank you for pointing out what I did not understand regarding the rs.
 
Upvote 0
Top