HTML Styles in TextView on Mono for Android - xamarin.android

I have this situation in my strings.xml.
<string name="mensagem">Olá <b><i> {0} </i></b>,</string>
And in my code I do this:
string msg = String.Format(Resources.GetString(Resource.String.mensagem).ToString(), cliente.Nome.ToUpper());
lblNome.Text = Html.FromHtml(msg).ToString();
But the style tags (b,i) do not work. I need to concatenate words with and without style, so I need to do it in this way. I cant use setTypeface because I need to style individual words and after that, join those words on a sentence.
What is the way ?
Regards,
Marcelo.

You need to change your code to the following.
string msg = String.Format(Resources.GetString(Resource.String.mensagem).ToString(), cliente.Nome.ToUpper());
lblNome.TextFormatted = Html.FromHtml(msg);
Html.FromHtml(string).ToString() is just converting the formatted ISpannable back to a string so you are losing the formatting.

Related

Currency cells and PHPSpreadsheet: How to read the currency from it?

I have an Excel (XLSX) file with a column containing values in different currencies, e.g. "CAD 4711.00", "NOK 56.78", "CHF 123.45".
Now I try to read data from these cells and I just cannot get the currencies. The best I can do is get the value (4711, 56.78, 123.45) but I also need to figure out which currency the cell is in. How can I do this?
I would be relatively happy if I could just get the formatted value but I do not see a way to do that either.
maybe this helps to get started :
$fileExcel = 'mony.xlsx';
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($fileExcel);
$sheet = $spreadsheet->getActiveSheet();
$lsValue = $sheet->getCell('A1')->getValue();
$lsFormat = $sheet->getStyle('A1')->getNumberFormat()->getFormatCode();
echo $lsValue .':'. $lsFormat .'<HR>';
the result is something like that:
123:#,##0.00\ "€"
123.12:#,##0.00\ [$EUR]
3123:#,##0.00\ [$₽-444]
split the format and inspect it further for your currency

Dart Markdown package, how to handle new lines

I am trying to make a WYSIWYG internal tool. And we decided to implement this feature with contentEditable. However, we save data to our databases in markdown. So I have to be able to parse from html to md and back. For html to md I use package html2md and for the other way around I use Markdown package.
The issue i've been having is that when you write to my editor text like
HEY
After many lines some text
It produces this in md
HEY
After many lines some text
Notably it uses 2 whitespace and 2 LF characters (or atleast i think so but i might be slightly wrong.) I solved this issue by parsing it like this
markdownToHtml(data.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'), inlineSyntaxes: [TextSyntax(String.fromCharCodes([32,32,10,10]),sub: "<div><br></div>")],inlineOnly: true );
The inline only parameter was neccesary because without it the text syntax wasnt applied for some reason. However this inline only then bit me in the arse when I tried to implement parsing of unordered lists, which are parsed as blocks. So I need a way to correctly parse these empty lines without using inline only.
class EmptyLineBlockSyntax extends BlockSyntax{
RegExp get pattern => RegExp(r'^(?:[ \t][ \t]+)$');
const EmptyLineBlockSyntax();
Node parse(BlockParser parser) {
parser.encounteredBlankLine = true;
parser.advance();
return Element('p',[Element.empty('br')]);
}
}
return markdownToHtml(data.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'), blockSyntaxes: [EmptyLineBlockSyntax()]);

How to deal with dynamic urls with special characters like single quote?

I am generating dynamic an "a href" html tag on my asp page. Also the url is dynamic. Sometimes there are special characters inside the url and the hyperlink is not working. For example when there is an single quote:
http://myCompany.com/'s-hertog.aspx
How can I fix this that the dynamic url always will work?
I already try this, but is not working:
string hyperLinkHtml = string.Format("<span class=\"bw-NewsQueryWebpart-BodyItemTitle\"><a href='{0}' >{1}</a>", HttpUtility.UrlEncode(newsItem.Url), newsItem.Title);
I found the solution by my self. I changed the single quotes to double quotes in the string.format:
string hyperLinkHtml = string.Format("<span class=\"bw-NewsQueryWebpart-BodyItemTitle\"><a href=\"{0}\" >{1}</a>", HttpUtility.UrlEncode(newsItem.Url), newsItem.Title);

NSString to NSDictionary

I have a string (from HTTP Header) and want to split it into a dictionary.
foo = \"bar\",baz=\"fooz\", beta= \"gamma\"
I ca not guarantee that the string is the same every time. Maybe there are spaces, maybe not, sometimes the double quotes are escaped, sometimes not.
So I found the solution in PHP with regular expressions. Unfortunately I can't convert it to work on iOS.
preg_match_all('#('.$key.')=(?:([\'"])([^\2]+?)\2|([^\s,]+))#', $input, $hits, PREG_SET_ORDER);
foreach ($hits as $hit) {
$data[hit[1]] = $hit[3] ? $hit[3] : $hit[4];
}
Can anybody help me converting this to Objective-C?
I met a guy which is kinda RegEx guru. He explained the whole stuff and I got the following (working!!!!) solution in RegEx.
This gives me strings like foo="bar":
(?<=[,\\s])((realm|qop|nonce|opaque)=(?:([\"'])([^\2]+?)\2|([^\\s,]+)))
I then use another RegEx to split it by key and value to create a dictionary.

XML Parsing - node.text method removing trailling spaces

I have a big xml file which i'm parsing using jscript. I have used the following code to load the xml
var xmlDoc = Sys.OleObject("Msxml2.DOMDocument.6.0");
xmlDoc.async = false;
// Load xml data from a file
xmlDoc.load(this._studyDocPath);
Now if i use the following code
var text = this.xmlDoc.selectSingleNode(xPath);
text = node.text;
the text variable holds the innertext of a perticular tag. But if I have tag like this
<Text>ABCD </Text>
then the node.text returns me only the value 'ABCD' i.e. it automatically trims the space. But I dont need to trim any trailling spaces. I need the text as it is. How can I achieve that?
Looking forward to your response
Thanks in Advance
We can use node.firstChild.nodeValue with a null check on node.firstChild

Resources