|
@@ -238,41 +238,43 @@ The following are some examples of how to use the various invocations of the
|
|
|
``String.format`` method.
|
|
|
|
|
|
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| **Type** | **Style** | **Example** | **Result** |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Dictionary | key | "Hi, {name} v{version}!".format({"name":"Godette", "version":"3.0"}) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Dictionary | index | "Hi, {0} v{1}!".format({"0":"Godette", "1":"3.0"}) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Dictionary | mix | "Hi, {0} v{version}!".format({"0":"Godette", "version":"3.0"}) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Array | key | "Hi, {name} v{version}!".format([["version":"3.0"], ["name":"Godette"]]) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Array | index | "Hi, {0} v{1}!".format(["Godette","3.0"]) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
-| Array | mix | "Hi, {name} v{0}!".format([3.0, ["name":"Godette"]]) | Hi, Godette v3.0! |
|
|
|
-+------------+-----------+--------------------------------------------------------------------------+-------------------+
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| **Type** | **Style** | **Example** | **Result** |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Dictionary | key | ``"Hi, {name} v{version}!".format({"name":"Godette", "version":"3.0"})`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Dictionary | index | ``"Hi, {0} v{1}!".format({"0":"Godette", "1":"3.0"})`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Dictionary | mix | ``"Hi, {0} v{version}!".format({"0":"Godette", "version":"3.0"})`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Array | key | ``"Hi, {name} v{version}!".format([["version","3.0"], ["name","Godette"]])`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Array | index | ``"Hi, {0} v{1}!".format(["Godette","3.0"])`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Array | mix | ``"Hi, {name} v{0}!".format([3.0, ["name","Godette"]])`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
+| Array | no index | ``"Hi, {} v{}!".format(["Godette", 3.0], "{}")`` | Hi, Godette v3.0! |
|
|
|
++------------+-----------+------------------------------------------------------------------------------+-------------------+
|
|
|
|
|
|
Placeholders can also be customized when using ``String.format``, here's some
|
|
|
examples of that functionality.
|
|
|
|
|
|
|
|
|
-+-----------------+--------------------------------------------------+------------------+
|
|
|
-| **Type** | **Example** | **Result** |
|
|
|
-+-----------------+--------------------------------------------------+------------------+
|
|
|
-| Infix (default) | "Hi, {0} v{1}".format(["Godette", "3.0"], "{_}") | Hi, Godette v3.0 |
|
|
|
-+-----------------+--------------------------------------------------+------------------+
|
|
|
-| Postfix | "Hi, 0% v1%".format(["Godette", "3.0"], "_%") | Hi, Godette v3.0 |
|
|
|
-+-----------------+--------------------------------------------------+------------------+
|
|
|
-| Prefix | "Hi, %0 v%1".format(["Godette", "3.0"], "%_") | Hi, Godette v3.0 |
|
|
|
-+-----------------+--------------------------------------------------+------------------+
|
|
|
++-----------------+------------------------------------------------------+------------------+
|
|
|
+| **Type** | **Example** | **Result** |
|
|
|
++-----------------+------------------------------------------------------+------------------+
|
|
|
+| Infix (default) | ``"Hi, {0} v{1}".format(["Godette", "3.0"], "{_}")`` | Hi, Godette v3.0 |
|
|
|
++-----------------+------------------------------------------------------+------------------+
|
|
|
+| Postfix | ``"Hi, 0% v1%".format(["Godette", "3.0"], "_%")`` | Hi, Godette v3.0 |
|
|
|
++-----------------+------------------------------------------------------+------------------+
|
|
|
+| Prefix | ``"Hi, %0 v%1".format(["Godette", "3.0"], "%_")`` | Hi, Godette v3.0 |
|
|
|
++-----------------+------------------------------------------------------+------------------+
|
|
|
|
|
|
Combining both the ``String.format`` method and the ``%`` operator could be useful as
|
|
|
``String.format`` does not have a way to manipulate the representation of numbers.
|
|
|
|
|
|
-+-----------------------------------------------------------------------+-------------------+
|
|
|
-| **Example** | **Result** |
|
|
|
-+-----------------------------------------------------------------------+-------------------+
|
|
|
-| "Hi, {0} v{version}".format({0:"Godette", "version":"%0.2f" % 3.114}) | Hi, Godette v3.11 |
|
|
|
-+-----------------------------------------------------------------------+-------------------+
|
|
|
++---------------------------------------------------------------------------+-------------------+
|
|
|
+| **Example** | **Result** |
|
|
|
++---------------------------------------------------------------------------+-------------------+
|
|
|
+| ``"Hi, {0} v{version}".format({0:"Godette", "version":"%0.2f" % 3.114})`` | Hi, Godette v3.11 |
|
|
|
++---------------------------------------------------------------------------+-------------------+
|