我有一個Label這樣的:
new Label
{
FontFamily = FontAwesome.Light,
FontSize = 50,
TextColor = Palette.Common.Accent,
BackgroundColor = Color.Transparent,
HorizontalTextAlignment = TextAlignment.Start,
VerticalTextAlignment = TextAlignment.Center,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center
}
.Bind(Label.TextProperty, nameof(MyFieldModel.iconCode))
iconCode在MyFieldModel是一個string。
string iconCode = "f135";
這只是呈現為文字字串f135而不是 Rocket。(f135 是 fontawesome 中火箭的代碼)。
但是當我將其更改為:
string iconCode = "\uf135";
它呈現為火箭。
如果我得到string像“f135”這樣的圖示代碼輸入。如何將其轉換為\uf135代碼格式。
我嘗試了以下所有方法,但沒有一個有效:
// try 1
string iconCode = "\\u" myCodeString;
// try 2
string iconCode = @"\u" myCodeString;
// try 3
StringBuilder sb = new StringBuilder();
sb.AppendFormat("U {0:X4} ", iconCode);
我如何使它作業?
uj5u.com熱心網友回復:
基于https://stackoverflow.com/a/9303629/199364,嘗試
= System.Text.RegularExpressions.Regex.Unescape(@"\u" myCodeString);
例如,如果myCodeStringcontains "f135",這相當于
= System.Text.RegularExpressions.Regex.Unescape(@"\uf135");
這應該給你相同的結果:
= "\uf135";
包含該單個 Unicode 字符的字串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/473726.html
