How to decode special character in Xamarin forms? - xamarin

How to decode spacial character in xamairn forms
Inside my label text = "Sample & Text"
instead of showing original text, its showing "Sample & Text"
so how to solve this?

& is used for displaying & in XAML. If you want to display Sample & Text on code behind, there's no need to encode it to Sample & Text. You could set the value directly. i.e. here is a list view's items source:
var list = new List<string>();
for (int i=0; i<10; i++)
{
var str = "Sample & Text";
list.Add(str);
}
listView.ItemsSource = list;
It shows correctly:
However, if your original text from the server is Sample & Text and you want to display the decoded format, you can try System.Net.WebUtility.HtmlDecode():
var str = System.Net.WebUtility.HtmlDecode("Sample & Text");

Try this:
<Label Text="Sample &Text"/>
This will display "Sample & Text"

Related

Indesign Script: Looping ALL paragraphs (including in overset)

Looking for a selector of ALL paragraphs in the selected TextFrame, including the "not visible ones" in the overset. Script is already working and looping through the visible paragraphs:
[...]
if(app.selection[0].constructor.name=="TextFrame") {
var myParagraphs = app.selection[0].paragraphs; // only visible ones?!
var myArray = myParagraphs.everyItem().contents;
for (var i=0; i<myArray.length; i++) {
// do some fancy styling - WORKING
myParagraphs[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.item('Format XYZ');
}
}
myArray.length changes when I set another hight for the TextFrame. But how can I work with ALL paragraphs? Already tested .anyItem() with the same result :(
Well, the paragraphs in the overset are not paragraphs of the text frame, so it makes sense that they are skipped in your script. To access all the paragraphs of the text frames + those that are in the overset part, you will need to access all paragraphs of the parent story (a story is the text entity that describes all the text within linked text frames and the overset text) of the text frame.
You can do so like this:
if(app.selection[0].constructor.name === "TextFrame") {
var myParagraphs = app.selection[0].parentStory.paragraphs;
for (var i = 0; i < myParagraphs.length; i++) {
myParagraphs[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Format XYZ");
}
}
Be aware though that this will handle all paragraphs in all text frames that are linked to your text frame in case there are any of those.
Also, since it looks like you need to apply the paragraph style on each paragraph of the entire story, you might as well apply the paragraph style to the entire story directly instead of looping over the paragraphs:
app.selection[0].parentStory.appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Format XYZ");

With NPOI, set Word paragraph to Heading 1 style

When using NPOI to create a Word document, how does one set a paragraph to the built-in "Heading 1" style?
Here is what I have tried in F#:
let doc = XWPFDocument()
let p = doc.CreateParagraph()
p.Style <- "Heading 1"
let r = p.CreateRun()
r.SetText("Hello, world")
When I open the generated file in Word, the line "Hello, world" is not in the Heading 1 style.
Here is what I did:
Using Word,
Create a new Blank document.
Include a paragraph that has the style(s) of interest.
Save the document to your project folder.
In code using NPOI,
Load the blank document.
Delete the contents of the document.
Write to your document, setting the paragraph style with the styleId.
Here is an example:
use fsSrc = new FileStream("blank.docx", FileMode.Open, FileAccess.Read)
let doc = XWPFDocument(fsSrc)
while doc.RemoveBodyElement(0) do ()
let p = doc.CreateParagraph()
p.Style <- "Heading1"
let r = p.CreateRun()
r.SetText("Hello, world")
Today I learned...
The default styles are not included when creating a new XWPFDocument().
The styles are identified by their styleId, not their user friendly names. The styleId for "Heading 1" is Heading1.

Access ListView item text (FMX)

I have a TListView and when the user clicks on the image of an item (big green dot in picture below) i want to copy the item text ("russtest.cfg") and subitem text ("My Device, 1991") to display in a ShowMessage. I can't find how to do it in C++ Builder but this link shows how in Delphi.
Below is the code i've tried in the TListView's ItemClickEx method:
TListItem* item;
item = ListView1->Items->Item[ItemIndex];
UnicodeString s;
s = item->ToString();
ShowMessage(s);
But it brings back this:
EDIT 1: Added the code i use to populate the ListView:
TListViewItem* item2Add = Form1->ListView1->Items->Add();
Form1->ListView1->BeginUpdate();
item2Add->Text = mystring3; // e.g. "russtest.cfg"
item2Add->Detail = mystring2; // e.g. "My Device, 1991"
item2Add->ImageIndex = 1; // big green dot
Form1->ListView1->EndUpdate();
Your need to typecast the TListItem* to TListViewItem*, then you can access its Text property:
TListViewItem* item = static_cast<TListViewItem*>(ListView1->Items->Item[ItemIndex]);
String s = item->Text;
ShowMessage(s);

NPOI XWPF how can I place text on a single line that is both left & right justified?

I'm new to using NPOI XWPF and trying to create my first document, so far it's going well. The only issue I have left is trying to place text on the same line that is both left and right justified, I want it to look like:
Area: 1(Left Jstfd) Grade Level/Course: 10th Grade Reading (Right Jstfd)
Below is the code snippet I'm using, it's just pushing all the text together on the left side of the page...blah
XWPFParagraph p2 = doc.CreateParagraph();
p2.Alignment = ParagraphAlignment.LEFT;
XWPFRun r3 = p2.CreateRun();
r3.SetBold(true);
r3.FontFamily = "Times New Roman";
r3.FontSize = 12;
r3.SetText("Area: " + ah.schoolArea);
XWPFRun r4 = p2.CreateRun();
r4.SetBold(true);
r4.FontFamily = "Times New Roman";
r4.FontSize = 12;
r4.SetText("Grade Level/Course: " + ah.filterParm);
Before trying to accomplish a task in (N)POI, it's always good to realize how said task is accomplished in Microsoft Word itself. You can't simply split a paragraph half-way a line, what you do is
Add a tab stop at the end of the line
Set it to right-aligned.
Type text on the left, hit tab, type text on the right
Unfortunately, it doesn't seem XWPFParagraph exposes tabstop functionality at this point. However, XWPFParagraph is a wrapper around the CT_P class, which maps 1:1 onto the underlying Office XML format. Using reflection, we can access this private field and use it to directly add the tabstop.
Sample code:
var paragraph = document.CreateParagraph();
var memberInfo = typeof(XWPFParagraph).GetField("paragraph", BindingFlags.NonPublic | BindingFlags.Instance);
if (memberInfo == null)
{
throw new Exception("Could not retrieve CT_P from XWPFParagraph");
}
var internalParagraph = (CT_P) memberInfo.GetValue(paragraph);
CT_PPr pPr = internalParagraph.AddNewPPr();
CT_Tabs tabs = pPr.AddNewTabs();
CT_TabStop tab = tabs.AddNewTab();
tab.pos = "9000";
tab.val = ST_TabJc.right;
var run = paragraph.CreateRun();
run.SetText("Left aligned");
run.AddTab();
run = paragraph.CreateRun();
run.SetText("Right aligned");
Result:

VBA command to autofit the text size in TextFrame2

I have the following code snippet to add a slide to the end of a Microsoft PowerPoint presentation and designate a title / subtitle:
longSlideCount = ActivePresentation.Slides.Count
With ActivePresentation.Slides
Set slideObject = .Add(longSlideCount + 1, ppLayoutTitle)
End With
' ------------------------------ make the main title ------------------------------------- '
slideObject.Shapes(1).TextFrame.TextRange.Text = "This is the Main Title Text"
slideObject.Shapes(2).TextFrame.TextRange.Text = "This is the SubTitle Text"
Is it possible to shrink / grow the text in the title string to fit on one line in the text frame?
Use .Textframe2.Autosize = msoAutoSizeTextToFitShape

Resources