Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>String.Length</h2> <p>Returns the length of the string (number of characters).</p> <p><strong>C#</strong></p> <pre><code>string MyString = "Stack Overflow String"; Response.Write(MyString.Length); </code></pre> <p><strong>VB.net</strong></p> <pre><code>Dim MyString As String = "Stack Overflow String" Response.Write(MyString.Length); </code></pre> <p><strong>MSDN Reference</strong></p> <p><a href="http://msdn.microsoft.com/en-us/library/system.string.length.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.string.length.aspx</a></p> <h2>Physical String Size Serverside</h2> <blockquote> <p>I'm not sure why so many people are apparently determined to put forward the idea that it is 'flat out impossible' to do this server side, it isn't. You just need to be a little bit creative, and be willing to do a lot of testing.</p> </blockquote> <p>There is no native function I know of to measure the pixel dimensions of a string. You can achieve it in the following ways. Note you need to know:</p> <ul> <li>The font family</li> <li>Font size</li> <li>Container dimensions (for when the text wraps lines)</li> <li>Any other CSS rules such as word spacing are going to make the calculation a lot less accurate and more complex. Try and avoid it if accuracy is important.</li> </ul> <p><strong>1. Render it to an image and measure image size</strong></p> <p>Draw the text to a bitmap, and then measure it. This should be reasonably exact.</p> <p><strong>2. Use a fixed width font</strong></p> <p>If you are using a fixed width font and the text doesn't wrap, you can simply multiply its width by the number of characters.</p> <p><strong>3. Rough estimation</strong></p> <p>You could get a reasonably rough estimation on non fixed width fonts by picking some arbitrary character width number and multiplying it by total characters. Depends how accurate you want to be. </p>
    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. 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.
    3. 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