Skip to content

Features: Literal Strings in String Formatting

Rudy Huyn edited this page Aug 1, 2019 · 1 revision

When using String Formatting, you can replace one or many parameters by one a literal string. ReswPlus will automatically insert it in your template string.

Key Value Comment
DownloadOurApp Download our apps in {0} #Format["Microsoft Store"]

will generate the following code:

public static string DownloadOurApp
{
    get
    {
        return string.Format(_resourceLoader.GetString("DownloadOurApp"), "Microsoft Store");
    }
}

Example

XAML:

<TextBlock Text="{x:Bind strings:Resources.DownloadOurApp}" />

Result:

Download our apps in Microsoft Store

Use Literal Strings + Parameters

You can use literal strings in addition to parameters for string formatting.

Key Value Comment
DonateToOurAssociation Hey {1}, donate {2:C2} to {0}! #Format["WWWF", String username, Int amount]

will generate the following code:

public static string DonateToAssociation(string username, int amount)
{
    return string.Format(_resourceLoader.GetString("DonateToAssociation"), "WWF", username, amount);
}

Usage

<TextBox
    x:Name="YourNameTextBox"
    Header="Enter your name"
    Text="Joe" />
<Slider
    x:Name="AmountSlider"
    Header="Amount"
    Maximum="127"
    Minimum="0"
    Value="35" />
<TextBlock
    Margin="0,12,0,0"
    FontWeight="Bold"
    Text="{x:Bind strings:Resources.DonateToAssociation(YourNameTextBox.Text, (x:Int32)AmountSlider.Value), Mode=OneWay}" />

Result: