Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As the OP insists on the use of <code>String.Format</code>:</p> <pre><code>string input; //the input of your textbox int temp = int.Parse(input); //parse your input into an int //the Format() adds the decimal points, the replace replaces them with the / string output = String.Format("{0:0,0}", temp).Replace('.', '/'); </code></pre> <p>The important step here is to cast the text of your textbox into an integer, as this simplifies the insertion of the decimal points with <code>String.Format()</code>. Of course, you have to make sure that your textbox is a valid number upon parsing or you may get an exception.</p> <hr> <p><strong>EDIT</strong></p> <p>So... you have some <em>dynamic-length</em> number and want to format it using a <em>static</em> format-string (as regexes, string replaces, ling or any c# code at all (!) are a no go)? This is impossible. You HAVE TO have some dynamic code creating a format string somewhere.<br> Without referencing to regexes or string replaces again, here is some code to create a format string depending on your input number.<br> This way you have just one <code>String.Format()</code> call. Perhaps you can put the algorithm to create the format string somewhere else and just call it from whereever you need it.</p> <pre><code>string input; //the input of your textbox int temp = int.Parse(input); //parse your input into an int string customString = "{0:"; string tempS = ""; for (int i = 0; i &lt; input.Length; i++) { if (i % 3 == 0 &amp;&amp; i != 0) { tempS += "/"; } tempS += "#"; } tempS = new string(tempS.Reverse().ToArray()); customString += tempS; customString += "}"; string output = String.Format(customString, temp)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload