Find the length of a string in pixels

Hello all,
Wondering if there's a way in PowerShell to find the length of a given string in pixels?

That would depend on the font used to draw it, including size, bold / italic, etc.  Assuming you know those things, there's a TextRenderer.MeasureText method in the Windows Forms library:
$string = 'This is my string. There are many like it, but this one is mine.'
$font = New-Object System.Drawing.Font('Arial', 12, [System.Drawing.FontStyle]'Bold, Italic')
$size = [System.Windows.Forms.TextRenderer]::MeasureText($string, $font)
$size.Width

Similar Messages

  • How do i find the length of a string??

    trying to use the substring, I know the beginIndex (in my case 10), but the string will vary in size and so i need to find the last character and set it as the endIndex, how do i do this?
    public String substring(int beginIndex,
    int endIndex)Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
    Examples:
    "hamburger".substring(4, 8) returns "urge"
    "smiles".substring(1, 5) returns "mile"
    Parameters:
    beginIndex - the beginning index, inclusive.
    endIndex - the ending index, exclusive.
    Returns:
    the specified substring.

    Hi
    To substring the string where u know the begin index and want to extract till the end use the following function from the String class of the java.lang package
    String substring(int beginindex);
    String test = "Hello";
    String xx = test.substring(1);
    The Value stored in xx will be ello
    This is in case u need till the end of the String
    If wanna skip the last character u can
    use
    String substring(int beginindex,int endindex);
    String test = "Hello";
    String xx = test.substring(1,test.length()-1);
    The Value stored in xx will be ell

  • Finding the length of a string

    hi im pretty new to all this,
    I am adding a part to my very basic program where the user can type "y" or "n" after they are being asked if they want to continue, I have been able to do this ok but im trying to make the program as air-tight as possible and i'm having troubble with the error checking.
    I have told the program what to do next based on the first character the user has typed (character 0), I would like my prorgam to prevent continuation if more than one character was entered into the string. At present it still recognises ydr (example) as a valid entry, is there anyway i can detect if there is more than one character in the sting? by doing so i'll be able to throw back an error to the user.
    do
      System.out.println("Would you like to continue (y/n)");
      System.out.println("");
      tmpans = scan.nextLine();
          if (tmpans.length > 1)
          //i know the above method of detecting the length dosn't work with strings, is there an alternative?
            exchar = true;
            System.out.println("You have entered too many characters");
          else
            exchar = false;
          while (exchar);
          if (tmpans.charAt(0) == 'y')
    ... etc

    String.getLength()Errr... String.length() ?Ya right. Whatever. lol
    It's still early in the day for me

  • Find the length of a String, without using any String API

    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please help

    Simratpal wrote:
    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please helpWell I have strongly argued against doing this, (it seems like a pointless exercise), and I have even stated that it cannot be done, even Reflection at some level will use a String method. I have not bothered to dissect wether the same is true with JNI. However, if we take the statement of the original problem exactly as stated, particularly the
    but method should not have any String API.i.e. we don't care if a String API is used 'under the covers', just so long as there is no direct usage in the new method that is written, then the answer is trivially easy:
    public class Main
        public static void main(String args[])
            Main worker = new Main();
            String str = "123456789";
            int len = worker.strLenUsingNoExplicitStringClassMethod(str);
            System.out.println("Length of string \""+str+"\""+" is "+len);
        public int strLenUsingNoExplicitStringClassMethod(String string)
            StringBuilder sb = new StringBuilder(string);
            return sb.length();
    }

  • Finding the key according to string length in java.util.Properties

    Finding the key according to string length in java.util.Properties.
    I know only String length only.

    i need to retrieve the values from the java.util.properties.
    we know that we need to give the key value in order to retrieve the datas.
    but my problem is i will give the length of the key instead of giving the key value but i need to retrieve the datas according to the length of the key.

  • How is the length of a string calculated in Java?  and JavaScript?

    Hi all,
    Do any of you know how the length of a string is being calculated in Java and JavaScript? For example, a regular char is just counted as 1 char, but sometimes other chars such as CR, LF, and CR LF are counted as two. I know there are differences in the way Java and JavaScript calculate the length of a string, but I can't find any sort of "rules" on those anywhere online.
    Thanks,
    Yim

    What's Unicode 4 got to do with it? 1 characteris 1
    character is 1 character.
    strings now contain (and Java chars also) is
    UTF-16 code units rather than Unicode characters
    or
    code points. Unicode characters outside the BMPare
    encoded in Java as two or more code units. So it would seem that in some cases, a single
    "character" on the screen, will require two charsto
    represent it.So... you're saying that String.length() doesn't
    account for that? That sux. I don't know. I'm just making infrerences (==WAGs) based on what DrClap said.
    I assume it would return the number of chars in the array, rather than the number of symbols (glyphs?) this translates into. But I might have it bass ackwards.

  • Any method to find out length of a string !!

    Hello friends,
                  I used <i><b>describe</b></i> statement to find out the length of a string, but it actually returns the whole length of the string but not actual no. of char's in this.
    any one suggest a solution for this.
    Senthil

    Hi Senthil
    The ABAP function STRLEN returns the length of a string up to the last character that is not a space.
    [COMPUTE] <n> = STRLEN( <c> ).
    STRLEN processes any operand <c> as a character data type, regardless of its real type. There is no type conversion.
    As with mathematical functions, the keyword COMPUTE is optional.
    DATA: INT TYPE I,
    WORD1(20) VALUE '12345'.
          WORD2(20).
          WORD3(20) VALUE ' 4 '.
    INT = STRLEN( WORD1 ). WRITE INT.
    INT = STRLEN( WORD2 ). WRITE / INT.
    INT = STRLEN( WORD3 ). WRITE / INT.
    The results are 5 , 0, and 4 respectively.
    Regs
    vijay

  • Finding the length of a path

    hey,
    i'm using cs3 and i have a few simple paths (curves) and i'd like to know the length of these curves but i can't seem to find an option, or whatever, for that.
    thanks

    You mean the length as you travel along the curves?
    Can't be done I'm afraid, at least not very accurately.
    If it's really important you could try arranging a whole lot of little squares along the path so that they touch each other and then counting them. But the result won't be accurate unless the squares are very small.
    However, if you know how the curves are constructed geometrically you can sometimes calculate their lengths.
    For example if the curve is an arc of a circle and you know the angle it subtends as a proportion of 360 degrees then it's fairly easy to use pi to find the length of it.
    Circumference of a circle = pi x diameter.
    "As every skoolboy kno" (nigel molesworth)
    Ellipses are more of a bother and I don't know the formulas for sinus curves, parabolas and that sort of thing.

  • How to find the length of the resultset

    how to find the length of the resultset

    (Doing a select count as somebody suggested is nota
    good solution, as the count can change betweenyour
    count query and your real query.)And the number of rows can't change between getting
    the last one and doing the actual work?I don't think so. Once you've got the ResultSet, I don't think it will change under you, unless you explicitly set it to SCROLL_SENSITIVE.
    I could be mistaken though.

  • How to calculate the length of a string

    Hi everyone,
    A simple question. How to calculate the length of a string?
    Thanks!

    Hi Wuyia Nata,
      As everyone has suggested you search the forum before posting a question, i guess for basic questions u never have to post a question, you will get the answer in your search. Anyways see the code below for string lenght.
    Data:
      w_string type string,
      w_lenght type i.
    w_string = 'vhdskbvsdkbvdsvnsknvs'.
    w_lenght = strlen( w_string ).
    Write:
      w_lenght.
    With luck,
    Pritam.

  • How to Find the length of Infosource?/

    Hi BW Guru's,
    How to Find the length of Infosource?
    Thanks
    Bhima Chandra Sekhar G

    Hi Bhima,
    You can look up the transfer structure (extract structure) in table ROOSOURCE in the active version of the DataSource and determine its size via SE11 (DDIC) -> Utilities -> Runtime object -> Table length.
    Hope it helps!
    Bye,
    ROberto

  • Checking the length of a string in sapscript

    Is there a way to check the length of a string in sapscript?
    What I want to do is, if the length of two strings is greater than a certain ammount, truncate the string.
    But I don't know if is possible inside the sapscript

    Never mind, I did it with a perform instead

  • Length of a string in pixel

    Hello,
    I am programming a servlet which produces html pages. The page contains a table with more than one column. The columns have a static width of 200 pixel. Now, I want to put some strings into the cells of the table. Depending on the width in pixel, there shall be one ore more cells in a row reserved for one string. How do I know the width of a string in the browser in pixel?
    My idea was, to create a Label within the java-servlet with the right font and fontsize. Then I can get the length in pixel:
    pixellength = testLabel.getFontMetrics(theFont).stringWidth("string to measure");
    That works very well, if the Server has a GUI. If not, the following exception occurs:
    java.lang.NoClassDefFoundError at
    java.lang.Class.forName0(Native Method) at
    java.lang.Class.forName(Class.java:130) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) at
    java.awt.Font.initializeFont(Font.java:310) at
    java.awt.Font.(Font.java:346) at
    The servlet should work on non-GUI servers as well! What can I do now? Any ideas?

    Hi!
    I don't really know if I'm right on this, but:
    If U use nonproportional fonts (like courier) can't U calculate it by multipling the fontsize (which is in pixels) by the stringsize (number of characters)? i.e.: "Teststring" in fontsize 15 would be 150 pixels wide?
    Thomas.

  • Chnage colum from CLOB to Varchar2 and find the length of CLOB

    Hi,
    I have got tables contain CLOB fields. I want to converter them to varchar2? Is the a way to do it? how can I find the max of length the data in CLOB fields.
    Thanks in advance!!
    Michael

    Hi All,
    Thanks you for your useful information. What I need is to change the colum data type (definaition itself)from CLOB to Varchar2, not just to display the values in CLOB field into varchar2. I have tried to change the date type from COLB to varchar2 in TOAD and got ORA_22859: invaliad modification of columns.
    Any suggestions?
    Many Thanks
    Michael

  • How can i get the length of a string with Simplified Chinese?

    when i use eventwriter to add content to a xmldocument,there are some chinese simplified string in it,i use String.length() for the length ,but it is not correct~how can i get the right length for eventwriter?

    Below is a simple patch for this problem. Using this patch you need to pass 0 as the length argument for any XmlEventWriter interfaces that take a string length.
    Regards,
    George
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp    Fri Nov  3 12:26:11 2006
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp      Thu Mar 15 13:58:13 2007
    *** 234,239 ****
    --- 234,241 ----
            CHECK_NULL(text);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)text);
            if (!_current)
                    throwBadWrite("writeText: requires writeStartDocument");
            try {
    *** 413,418 ****
    --- 415,422 ----
            CHECK_NULL(dtd);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)dtd);
            if (_current) {
                    if (!_current->isDoc())
                            throwBadWrite("writeDTD: must occur before content");
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp Tue Jan  2 16:01:14 2007
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp   Thu Mar 15 13:59:25 2007
    *** 326,331 ****
    --- 326,333 ----
                    needsEscape = false;
            else
                    needsEscape = true;
    +       if (!length)
    +               length = ::strlen((const char *)chars);
            writeTextWithEscape(type, chars, length, needsEscape);
    *** 336,341 ****
    --- 338,345 ----
                                  bool needsEscape)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)chars);
                    if ((type == XmlEventReader::Characters) ||
                        (type == XmlEventReader::Whitespace)) {
                            char *buf = 0;
    *** 381,386 ****
    --- 385,392 ----
      NsWriter::writeDTD(const unsigned char *data, int len)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)data);
                    _stream->write(data, len);
      }

Maybe you are looking for

  • Regarding Jdeveloper ---- Urgent

    Hi All, We got a project in iStore Customization....for that which version of Jdeveloper can i download ? and How can i do iStore customization? Is there any documents are there ...plz tell it also ... In Forums i am not able to find the iStore relat

  • WRT320N Wifi after Day or two loses connection

    Hello I have a problem that over time I no longer work Wifi connection. LAN connection is OK.  After the restart everything is OK, but only 1 or 2 days. Then I must reboot again. Latest Firmware WPA 2 Personal no ssid broadcast (did not help either t

  • I am trying to download ITune and keep getting message Apple application not found. Error 2

    I am trying to Download ITunes to my PC and keep receiving a message " Apple Application Support not found. Error 2.  The installation will not complete.

  • Outer join on multiple tables

    Hi All, I need to create multiple outer join in Discoverer. My requirements is like this I have a report where in I show the sales of components. I have Year as page item in Discoverer cross tab. I have 2 years in my year table, 1999 and 2000 in the

  • Possibility to uninstall trial version even if i have put the documents to the trash ?

    hi, some days ago, I have downloaded the Photoshop trial version. But it didn't open correctly then I decided to put it in the trash (and empty it...) to download a new trial version, hoping that the new one could work better than the previous one. B