Using the Text widget with text that's read from disk, that contains new line characters \n, does not go to new line. Anyone have suggestions of how I can get around this? The text in the file is
The code for the image you see above is as follows:
Text(valueFromFile, style: TextStyle(color: Colors.red))
My text is being read from an Xml file that is contained in my assets folder.
The comment from uaraven above
Does your file contain actual '\n' characters? If so then that's not a new line character ...
Helped me come up with a solution. Since the Text Widget is interpreting the \n characters as normal characters, I just did a replace on it and inserted the actual escape character.
var correctlyEscapedString = valueFromFile.replaceAll('\\n', '\n');
Text(correctlyEscapedString, style: TextStyle(color: Colors.red));
final String someText =
"This is your line number one\n\n"
"This is your line number two\n\n"
"This is your line number three\n\n"
"This is your line number four\n\n"
"This is your line number five\n\n";
this is one option for you.
int maxLines
final
An optional maximum number of lines for the text to span, wrapping if
necessary. If the text exceeds the given number of lines, it will be
truncated according to overflow.
If this is 1, text will not wrap. Otherwise, text will be wrapped at
the edge of the box.
If this is non-null, it will override even explicit null values of
Text.maxLines.
Related
I am writing multi-lines in the file.
Number Name
Jack
The first line is a header.
I am going to write lines like the above format.
If the number is null, I am writing a line like this.
file.print "Jack".indentation("Number".length + 2)
There are 2 spaces between Number and Name in the header.
But it is showing like this since the length 6 spaces are not the same as "Number".
Number Name
Jack
Is there any solution to format better?
I need to use non printable characters in a String constant, but Xcode shows error in my swift file as "Unprintable ASCII character found in source file"
My Simple code is below
let unprintableCharInString = "12345"
You could see the non printable characters at prefix and suffix of above string value, If you just copy paste my above code in Sublime text or some other text editor which supports to show Unprintable characters.
But if you paste the above code in Xcode swift file, you will see the compiler error "Unprintable ASCII character found in source file".
And if I use the same string in Objective C as like below, there is no error.
NSString *unprintableCharInString = #"12345";
So how to use non printable characters in Swift string variable directly as like above Objective C code?
Note:
As the body text box trims those non printable chars while saving my question, you can't see those chars if you copy paste the code from here. Instead of that try to copy the above code by editing my question. So you can get those chars in Body text box during edit.
Screenshot from Sublime Text editor:
Thanks in advance!
To display space characters you can use XCode Editor > Show Invisibles. But I'm not really sure will it help in your case.
Based on the #Alladinian's suggestion in Comment above,
Answer is: We need to add the unprintable ASCII characters manually in source code while declaring string value.
Example:
let unprintableCharInString = "\u{02}123\u{1A}"
Here \u{02} is Hex value of "START OF TEXT (STX)" and \u{1A} is Hex value of "SUBSTITUTE (SUB)"
Thanks #Alladinian!
I need to update a bilingual dictionary written in Writer by first parsing all entries into their parts e.g.
main word (font 1, bold)
foreign equivalent transliterated (font 1, italic)
foreign equivalent (font 2, bold)
part of speech (font 1, italic)
Each line of the document is the main word followed by the parts listed above, each separated by a space or punctuation.
I need to automate the process of walking through the whole file, line by line, and place a delimiter between each part, ignoring spaces and punctuation, so I can mass import it into a Calc file. In other words, "each part" is a sequence of character (ignoring spaces and punctuation) that have the same font AND font-style.
I have tried the standard Search&Replace feature, and AltSearch extension, but neither are able to complete the task. The main problem is I am not able to write a search query that says:
Find: consecutive characters with the same font AND font_style, ignore spaces and punctuation
Replace: term found above + "delimiter"
Any suggestions how I can write a script for this, or if an existing tool can solve the problem?
Thanks!
Pseudo code for desired effect:
var delimiter = "|"
Go to beginning of document
While not end of document do:
var $currLine = get line from doc
var $currChar = get next character which is not space or punctuation;
var $font = currChar.font
var $font_style - currChar.font_style (e.g. bold, italic, normal)
While not end of line do:
$currChar = next character which is not space or punctuation;
if (currChar.font != $font || currChar.font_style != $font_style) { // font or style has changed
print $delimiter
$font = currChar.font
$font_style - currChar.font_style (e.g. bold, italic, normal)
}
end While
end While
Here are tips for each of the things your pseudocode does.
First, the easiest way to move line by line is with the TextViewCursor, although it is slow. Notice the XLineCursor section. For the while loop, oVC.goDown() will return false when the end of the document is reached. (oVC is our variable for the TextViewCursor).
Get each character by calling oVC.goRight(0, False) to deselect followed by oVC.goRight(1, True) to select. Then the selected value is obtained by oVC.getString(). To ignore space and punctuation, perhaps use python's isalnum() or the re module.
To determine the font of the character, call oVC.getPropertyValue(attr). Values for attr could simply be CharAutoStyleName and CharStyleName to check for any changes in formatting.
Or grab a list of specific properties such as 'CharFontFamily', 'CharFontFamilyAsian', 'CharFontFamilyComplex', 'CharFontPitch', 'CharFontPitchAsian' etc. Character properties are described at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Formatting.
To insert the delimiter into the text: oVC.getText().insertString(oVC, "|", 0).
This python code from github shows how to do most of these things, although you'll need to read through it to find the relevant parts.
Alternatively, instead of using the LibreOffice API, unzip the .odt file and parse content.xml with a script.
I would like to create a label with some unicode text and a music note. The notes are shown below:
I have tried:
titleLabel.text = #" title + ♫";
but that results in:
I must be doing something dumb.. Any advice welcome.
The number column in your table actually contains HTML/SGML/XML entities with decimal values. A unicode escape sequence in NSString takes the hexadecimal value, so your note ♫ would be the hex value 0x266b to be used like this
titleLabel.text = #" title \u266b";
Hit cmd+cntrl+space in Xcode, and search for 'note'. There are some u may use. Just double click one and it will be written where your cursor is in the code.
I'm currently trying to write a script which would run through a word document and output to a text file all the lines that are written in a certain font.
So if I had the document:
"This is the first line of the document.
This is the second line of the document.
This is the third line of the document."
And say normal lines are Times New Roman, bold is Arial, and italics is Sans Serif.
Then, ideally, I could parse the document for all lines in Arial and the text file output would have the line:
This is the second line of the document.
Any idea on how to do this from a script? I was thinking about first converting the doc into xml, but I do not think this is possible within a script.
You'll want to use the FIND object, and the FONT property of the FIND object.
So, something like this:
Public Sub FindTest()
Dim r As Range
Set r = ActiveDocument.Content
With r.Find
.ClearFormatting
.Style = "SomeStyleName"
Do While .Execute(Forward:=True, Format:=True) = True
'---- we found a range
Dim duperange As Range
Set duperange = r.Duplicate
Debug.Print r.Text
Loop
End With
End Sub
Note that where I've specified Style, you could specify font formatting via the FIND.FONT object, or various other formatting options. Just browse around the FIND object to see what's available.