Skip to content

Features: String Formatting

Rudy Huyn edited this page Aug 1, 2019 · 9 revisions

ReswPlus can generate strongly typed methods to format your strings.

How To

Simply add the tag #Format[...] in the comment column of your resw file and ReswPlus will automatically generate a method with strongly typed parameters.

Types supported

The identifier of the types supported are inspired by MIDL 3.0:

identifier C# Type VB Type C++/CX Type C++/WinRT Type
Byte byte Byte char char
Int/Int32 int Integer int int
UInt/Uint32 uint UInteger unsigned int unsigned int
Long/Int64 long Long long long
ULong/UInt64 ulong ULong unsigned long unsigned long
String string String Platform::String^ hstring
Double double Double double double
Char char Char wchar_t wchar_t
Decimal decimal Decimal long double long double
Object Object object Platform::Object^ IStringable

Example:

Key Value Comment
ForecastAnnouncement The temperature in {2} is {0}°F ({1}°C) #Format[Int32, Int32, String]

Named parameters

You can also indicate the name of parameters in addition to the type.

Example:

The resource:

Key Value Comment
ForecastAnnouncement The temperature in {2} is {0}°F ({1}°C) #Format[Int32 fahrenheit, Int32 celsius, String city]

will generate the following code, with strong type and named parameters based on the hashtag in the comment section):

#region ForecastAnnouncement
/// <summary>
///   Format the string similar to: The current temperature in {2} is {0}°F ({1}°C)
/// </summary>
public static string ForecastAnnouncement(int tempFahrenheit, int tempCelsius, string city)
{
	return string.Format(_resourceLoader.GetString("ForecastAnnouncement"), tempFahrenheit, tempCelsius, city);
}
#endregion

Reserved characters

To use " in your literal strings, you need to escape it and write \" instead.

Example: #Format["Welcome to my \"Home\"!"]

All other special characters used by ReswPlus (#, [, ], ,) don't need to be escaped.

Example: #Format["Hello [You]", "Welcome, come in!", "#hashtag"]

Clone this wiki locally