I'm trying to show currency symbols on the dropdown in my monodroid application.
As you know currency units contain some thing like "र". but when I run application, the drop down just show a rectangle instead of "र".
How I can make it human-readable?
EDIT
Actually I parse this json for accessing to the unit ( saving the name attribute to a string variable):
{"id":"167","name":"\u0930","type":"4","enabled":"1","tosi":"0.0182","index":"1","extra":"INR","extra2":"Indian Rupee","extra3":"India","extra4":"Paisa","seperator":",","d_seperator":"","after_before":"0"},
When I parse it, in run-time the string variable includes "र" but when I show it on the dropdown the device show a box.
So according to 'Sam' comment I use this code. I pass the string varible to method and show the return string to the dropdow. but yet I see a box :(
public static string ConvertUnitsEncoding(Activity act,string Encoded){
try {
if( Encoded =="र")
return act. Resources .GetString(Resource .String .IndianUnit );
else
return Encoded ;
} catch (Exception ex) {
RltLog .HandleException (ex);
return Encoded ;
}
}
You've got two options:
Either load a custom font that includes that special character:
TextView tv = (TextView)findViewById(R.id.tv);
// Put the font in the asset folder
Typeface tf = Typeface.createFromAsset(Context.Assets, "Symbol.ttf");
tv.setTypeface(tf);
Most of the installed fonts on Windows have a currency subset which includes currency symbols but not Rupee. I read somewhere that Microsoft Update will add the Rupee to the fonts but I don't have it on my system. I have found Amty Currency Font with Rupee support but I'm not sure how useful it would be for your case. Try it.
Or simply use a small image for that purpose. I would prefer this approach because it's platform independent and you can find lots of symbol icons out there. Something like this:
Related
Is there some way to see the logs of the Xamarin.Forms front-end?
I am somewhat familiar with Blazor, and typically you can see front-end errors by opening the Developer Tools => Console in the browser. There you will see errors and warnings, that typically would not manifest themselves in the debugging environment within C# or VS (as far as I am aware).
I am looking for an equivalent in Xamarin.Forms.
A specific example of where I would want this, is exceptions related to binding, in the view's .xaml file.
In my CategoryPage.xaml file, I am binding a hex color code, to the variable ColorCode:
<StackLayout BackgroundColor="{Binding ColorCode}" Padding="20">
Assuming everything else is working correctly, if I have an incorrect color hex value for the ColorCode variable I am binding, the BackgroundColor would default to white.
Looking at the symptomatic manifestation of the problem (a white BackgroundColor instead of whatever other color I expect), it may be hard to know the root cause.
Therefore, I'm looking for some log, that displays front-end exceptions, along the lines of "Error: Could not parse hex value 9C27B0", in the scenario I have described.
This would indicate to me that the binding does occur, but that I have an incorrect value in my repository. Instead of the front-end failing silently.
To begin with, Hex color starts with a pound sign or hashtag (#) and are followed by six letters (A-F) and/or number (digit from 0-9). Alphabetic characters may be uppercase or lowercase. So the ColorCode should follow this rule to make it valid.
Furthermore, you can use Regex to check whether a given string is a valid Hex code or not and then use System.Diagnostics.Debug.WriteLine(); to display it in the VS Output panel. I used a invalid data:#EFFA07A and it can be shown in the VS Output panel like below:
Here's the code below for your reference:
public partial class MainPage : ContentPage
{
private string _color;
public Color ColorCode
{
get => Color.FromHex(_color);
set
{
if (!(Regex.Match(_color, "^#[0-9a-fA-F]{6}$").Success))
{
System.Diagnostics.Debug.WriteLine("Error: Could not parse hex value: ");
}
else
{
if (Color.FromHex(_color) == value) return;
var a = Color.FromHex(_color);
a = value;
OnPropertyChanged(nameof(ColorCode));
}
}
}
public MainPage()
{
InitializeComponent();
ColorCode = Color.FromHex(_color = "#EFFA07A");
BindingContext = this;
}
}
I have a c# report that contains one String column represent the currency.
Now I try to convert the String value to currency:
= FormatCurrency(Fields!SOTIEN_GUI.Value, 0)
That works, but the value is now US currency (EX: $ 7.000)
What have I do to to get the result like "₫ 7.000" ?
Thanks.
I assume, you have created .rdlc report file. To set Current region settings, so to display currency in the format you'd prefer, you should to do next.
First, you should find Language report property. To do that, just click free place around you report objects. In the Properties window, VS will display the properties for the report.
Second, find there Language property, and change it to those, that you like. Btw, it's described here.
So, you'll get something like this:
Is this in some special context, like Excel or something? In regular C#, I think what you want to do is use something like:
moneyValue.ToString("C", new CultureInfo("vi-VN"));
Instead of using FormatCurrency you could use the ToString() Method.
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
you maybe take a look at this thread: How to format a string as Vietnamese currency?
as you can see it's possible to use the ToString() Method (or like in the example the string.Format() Method):
var value = 8012.34m;
var info = System.Globalization.CultureInfo.GetCultureInfo("vi-VN");
Console.WriteLine(String.Format(info, "{0:c}", value));
UPDATE May this post be helpful for coders using RichTextBoxes. The Match is correct for a normal string, I did not see this AND I did not see that "ä" transforms to "\e4r" in the richTextBox.Rtf! So the Match.Value is correct - human error.
A RegEx finds the correct text but Match.Value is wrong because it replaces the german "ä" with "\'e4"!
Let example_text = "Primär-ABC" and lets use the following code
String example_text = "<em>Primär-ABC</em>";
Regex em = new Regex(#"<em>[^<]*</em>" );
Match emMatch = em.Match(example_text); //Works!
Match emMatch = em.Match(richtextBox.RTF); //Fails!
while (emMatch.Success)
{
string matchValue = emMatch.Value;
Foo(matchValue) ...
}
then the emMatch.Value returns "Prim\'e4r-ABC" instead of "Primär-ABC".
The German ä transforms to \'e4!
Because I want to work with the exact string, i would need
emMatch.Value to be Primär-ABC - how do I achieve that?
In what context are you doing this?
string example_text = "<em>Ich bin ein Bärliner</em>";
Regex em = new Regex(#"<em>[^<]*</em>" );
Match emMatch = em.Match(example_text);
while (emMatch.Success)
{
Console.WriteLine(emMatch.Value);
emMatch = emMatch.NextMatch();
}
This outputs <em>Ich bin ein Bärliner</em> in my console
The problem probably isn't that you're getting the wrong value back, it's that you're getting a representation of the value that isn't displayed correctly. This can depend on a lot of things. Try writing the value to a text file using UTF8 encoding and see if it still is incorrect.
Edit: Right. The thing is that you are getting the text from a WinForms RichTextBox using the Rtf property. This will not return the text as is, but will return the RTF representation of the text. RTF is not plain text, it's a markup format to display rich text. If you open an RTF document in e.g. Notepad you will see that it has a lot of weird codes in it - including \'e4 for every 'ä' in your RTF document. If you would've used some markup (like bold text, color etc) in the RTF box, the .Rtf property would return that code as well, looking something like {\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid15946317\charrsid15946317 test}
So use the .Text property instead. It will return the actual plain text.
How do I change the default newline character from Windows \r\n to Unix style \n? Ideally I change the Environment somehow and have it done globally so I don't need to modify a bunch of string/textwriter code.
Unfortunately this is not really doable. The primary way by which developers embed new lines in their application is by using Enviornment.NewLine. This is a static property which returns Window style new lines
public static string NewLine {
get {
return "\r\n";
}
}
There is no way to modify the return of this property from your code.
Your best option for changing new line endings is to develop a library which converts known sources of embedding Windows new lines to unix ones. For example a stream and string converter would likely be in order.
We use a third-party PDF Generator library which requires that you specify the TrueType or Type1 file name when using a font other than the 14 or so that are part of the default PDF standard.
So if I want to use Bitstream Arrus Bold I have to know to reference arrusb.ttf.
Short of enumerating all of the files in the font folder and creating a disposable PrivateFontCollection to extract the relationships, is there a way to obtain the underlying font name from font information, i.e. given Courier New, Bold, Italic derive CourBI.ttf?
I've already looked at the InstalledFontCollection and there's nothing.
If you don't mind poking around in the registry, take a look at
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
It has pairs like
Name = "Arial (TrueType)"
Data = "arial.ttf"
You can do this the necessary queries like this:
static RegistryKey fontsKey =
Registry.LocalMachine.OpenSubKey(
#"Software\Microsoft\Windows NT\CurrentVersion\Fonts");
static public string GetFontFile(string fontName)
{
return fontsKey.GetValue(fontName, string.Empty) as string;
}
A call to GetFontFile("Arial (TrueType)") returns "arial.ttf"
You could of course modify the code to append the (TrueType) portion to the fontName, or to look through everything returned by fontsKey.GetValueNames() to find the best match.