I would not believe this if I wasn't seeing it with my own eyes.
string test = String.Format( "{0} test {1}", "Mark", 13 );
Results in a value of "{0} test {1}"
for variable test
string test = string.Format( "{0} test {1}", "Mark", 13 );
Results in a value of "Mark test 13"
for variable test
Whhhhahaaaaattt? This is Xamarin by the way. I am very baffled here. Visual Studio 8.0.4. I've assigned the value of test
to a UI element, logged it to LogCat, and viewed it with the debugger. They all agree on the odd value.
In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string.
What is toString()? A toString() is an in-built method in Java that returns the value given to it in string format. Hence, any object that this method is applied on, will then be returned as a string object.
The %s operator is put where the string is to be specified. The number of values you want to append to a string should be equivalent to the number specified in parentheses after the % operator at the end of the string value. The following Python code illustrates the way of performing string formatting.
If you are targetting Android, your String
class refers to java.lang.String
(not System.String
, which is aliased as string
in .NET)
It has Format method, but different placeholders https://developer.xamarin.com/api/member/Java.Lang.String.Format/p/System.String/Java.Lang.Object%5B%5D/
For expected placeholders check for example: https://dzone.com/articles/java-string-format-examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With