Limiting length of Strings....

Hello,
I'm just starting to learn Java, and I'm trying to set up a 30 character limit on a String input from the user. I'm using TextIO for the input.
Can anyone help me out with this?

You can't (in a cross-platform way) prevent them entering more than your limit, you can however, check, after they've entered their string, that strings length.
I hope this helps
Talden

Similar Messages

  • Calculate string CPI (length of string in pixel)

    Word-wrap position is at the moment done in SAP via length of string (count of letters) via function u201CRKD_WORD_WRAPu201D. But this is counting number of char, this give the problem that different font type and size give different word-wrap position ! -> We need to calculate if possible the word-wrap position via the relative length of text u2013 I tried to find some on SDN and Internet, the only thing I can find is some functionality in JAVA u2026
    Can any one help me how to calculate the length of a string using font type and hight of font... as we use truetype font as arial the length of letter "i" is not the same as 'X' ...
    Best regards Jørgen Jensen

    My problem is not to do the wordwrap, my problem is to find the right position as the length of 'i' is not the same length of 'X'
    example:
    iiiiiiiiii (10)
    XXXXXXXXXX(10)
    must be something like this:
    iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii(wordwrap position 35)
    XXXXXXXXXX(Wordwrap position 10)
    I need a way to find the length of a charactor in a given font and size.
    Best regards Jørgen Jensen

  • Getiing length of String in pixels.

    I need to set up legth of combobox depending on length of strings in it. Can I get length of String in pixels?

    You should use the getFontMetrics() method of the Graphics object used by the painting methods of the combo.
    Then the stringWidth(String) method of the given font metrics should give you the needed width.
    Just take care of the fact that the combo must be realized (set visible or packed) for this to work.

  • Determine length of string without function module

    hai experts,
    i need to know how to determine length of string without function module strlen'
    regards,
    karthik

    Please SEARCH in SCN before posting.

  • How to find length of string after encryption using DBMS_CRYPTO package

    Hi,
    I am planning do data encryption using DBMS_CRYPTO package. I want to find how much will be string length after encryption.
    e.g When I try to encrypt string of length between 1-15 characters it gives me encrypted string of 32 characters. When I try with 16 charcters encrypted string is of 64 characters.
    Is ther any formula to calculate length of encrypted string?
    Thanks
    Pravin

    The length change is dependent upon the algorithm you are using which can be a combination of cipher block, padding, and chaining.
    The best solution is determine the method you are going to use and apply it to the l ongest possible strings you are going to proces, then add some safety margin. There iis no penalty for defining your column as VARCHAR2(4000).

  • How to find Length of String

    Hi
    how to find length of a string.. i have a requirement that user cannot add more than 9 digits in a string.. i am new to WD Abap..
    Regards,
    Puneet

    Hi,
    You can use STRLEN command for your requirement.
    First read your input field using code wizard.
    Then using STRLEN command you can find the length of the Input field.
    For Example :
    Here input is your input field.
    data :    length type i.
    length = strlen(input).
    If length < 9.
    raise error msg.
    endif.
    Edited by: Viji on Mar 26, 2008 11:30 AM

  • Restricting the length of strings...

    I'm wondering if it is possible to restrict the length of a string produced by the String.valueOf(double) method. Here is an example:
    public class DoubleTest
         public static void main(String[] args)
              double d = 20.0;
              double d2 = 2.4;
              double value = (d/d2);
              String doubleString = String.valueOf(value);
              System.out.println(value);
    }This code will output "8.333333333333334" when run. Is there a way to restrict it to fewer decimal places, for example: "8.34"?
    Thanks a lot,
    Eric

    If you use DecimalFormat, you can specify the number of digits after the decimal point by using a 'pattern' in the constructor to DecimalFormat.
    Use '#' in the pattern for digits which will not show any leading zeros.
    Use '0' in the pattern for digits which will show zeros - this is the one to use after the decimal point to show how many decimal places you want showing.
    This format will round the numbers either up or down depending on which is nearer.
    See example below for usage :
    import java.text.*;
    public class DoubleTest{
         public static void main(String[] args)     {
              double d = 400000.0;
              double d2 = 2.4;
              double value = (d/d2);
              DecimalFormat df1 = new DecimalFormat("#.000");
            System.out.println(df1.format(value));
    }This returns 166666.667 (i.e. 3 places after the decimal, rounded up).
    Regards,
    Fintan

  • Maximum length of String

    Hi All,
    Do you know if there is a limit to the size of the string that can be submitted to Oracle database using OraOleDb?
    I wish to run SQL statements that can be very long and I get an error when I submit these statements. I have tried using versions 10.1 of OraOleDb also. Is there a setting in the Connection or query submission that would allow users to submit long strings to Oracle?
    Thanks

    OK, someone's bound to have a rant at IBM or WebSphere here, but a quick knock-up class in WSAD:
    public class StringTest {
         public static void main(String[] args) {
              System.out.println(">> StringTest >>");
              StringBuffer sb = new StringBuffer();
              for (int i=0; i<80000; i++) {
                   sb.append("-");
              String s = sb.toString();
              System.out.println("My String is " + s.length() + " bytes long.");
              System.out.println(">> StringTest []");
    }Gives me:
    StringTest >>My String is 80000 bytes long.
    StringTest []2 to the 16 is 65536, so that's certainly not the upper-limit for a String length in this case.
    And anyway, 2^16 is 18 in Java.

  • Possibility to define length of String fields for POJO Reporting

    <p>It would be a nice feature if you could set the length of a String field in POJO Reporting.</p><p>Right now the max length is set to 127 characters and that is not sufficient for our needs.</p><p>/Thanks</p><p>Mattias Melin</p><p>IST International</p><p>Sweden </p>

    Bascotie wrote:
    To make sure it was not blank I had been using
         if (aCust.state.equalsIgnoreCase("") || aCust.state.length() != 2){
    The first condition is redundant and pointless here, since, if it's true, the second one will always be true.

  • Determine length of string

    In a print statement ie System.out.print(String), how can you ensure that the string will take up a specific number of spaces, for tabulation purposes.

        public final static String padRight(String theString, char thePadChar,
                             int len) {
         if(theString.length() >= len)
             return(theString);
         else
             return(theString +
                 replicate(thePadChar, len - theString.length()));
        public final static String replicate(char c, int count) {
         StringBuffer sb = new StringBuffer();
         for(int i = 0; i < count; i++)
             sb.append(c);
         return(sb.toString());

  • How to check length of string attribute(from viewobject) on jspx ?

    Hi,
    JDEV : 11.1.1.4
    I am using carousel component inside that i am using Descrip attribute to show the content on carousel item,
    Now i want to display a more link , whenever the length of Descrip is greater than 150 characters.
    Currently from backing bean i am setting the chklength property based on length to true or false but the problem is i need to set a partial target
    and because of that my carousel component i getting refreshed every time.. is there any way to check the length in jspx page itself inside the vissible property
    this is my code
    <af:outputText value="#{item.bindings.Descrip.inputValue}"
                                                             id="ot49"/>
                                               <af:commandImageLink text="more.." id="moreid" shortDesc="click to see more.."
                                                                     visible="#{pageFlowScope.chklength}">
                                                <af:showPopupBehavior popupId="::p1"/>
                                                </af:commandImageLink>              thanks
    Gopinath

    i have added taglib like this,
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    but its showing error on below expression
    visible="${fn:length(item.bindings.Descrip.inputValue) > 150}"
    error : BooleanSimnpleTypeConvertor:"${fn:length(item.bindings.Descrip.inputValue) > 150}" cannot be converted to this type

  • Decoding Run Length Encoded String

    I have a class that reads data from a server using a BufferedReader. The data is read into a char[]. This data has been Run Length Encoded by a seperate process.
    I loop through the char[] looking for a sentinal value. Once this value is found, I look at the next char to find the length and then the next char to find the value that needs to be populated.
    In order to correctly determine the length, I & the char with 0xff. This works most of the time. What I am seeing is that in certain circumstances the value is not what I expect. For example, in the following hex representation:
    F0 8B 20
    FO is my sentinel. 8B tells me to pad for 139. And, 20 tells me the value is a Space. So my class should at this point add 139 spaces.
    However, even though I & the char with 0xff it interprets the decimal value as 57.
    Here is the Method that does the UnRLE:
    public static CharArrayWriter UnRle(char[] InBuffer)
            try {
                CharArrayWriter caWriter = new CharArrayWriter();
                if (IsRle(InBuffer)) {
                    int iLoop = 0, iByteRepeat = 0;
                    for (int iIdx = RLE_HEADER.length() + RLE_SENTINEL_LEN; iIdx < InBuffer.length; iIdx++) {     // Start after header
                        if (InBuffer[iIdx] == RLE_SENTINEL) {
                            if (InBuffer[iIdx + 1] == RLE_SENTINEL)                           
                                caWriter.write(RLE_SENTINEL);
                            else {                       
                                for (iLoop = 0; iLoop < (int)InBuffer[iIdx + 1] & 0xff; iLoop++)
                                    caWriter.write(InBuffer[iIdx + 2]);
                                iIdx += 2;
                        else
                            caWriter.write(InBuffer[iIdx]);
                else
                    caWriter.write(InBuffer);
                return caWriter;
            catch (Exception e) {
                System.err.println("UnRle Exception " + e.toString());
                return null;
        }Any ideas?
    Thanks,
    ABumgardner

    Readers and Writers expect to deal with 16-bit characters. You need to be using InputStream and OutputStream.

  • Generate fixed-length unique strings

    Hi all,
    I'm trying to generate 16 byte unique string from two input strings. Essentially, the unique string will be used as primary key in the database. The two input strings are (siteUrl, productId) in which siteUrl is the url of a website which has one or more productId. Each productId in a site is unique but there might be duplicate productIds from different sites. I want to generate 16 byte ids from each pair of (siteUrl, productId) such that they are unique (or have a very small chance of collision). Has anyone done this before? Please share your experience! Thanks heap!

    >>>>>
    KajThanks for the answer. However, what I want toknow
    is how to convert say productId to unique 8
    byte
    string. Any idea?What does the product id look like?Product id is usually a string of digits andletters:
    2323, 234lasfd1kj3,....
    What I'm looking for is a hash function h suchthat:
    h(siteUrl) -> 8 byte string
    h(productId) -> 8 byte string
    I now can combine h(siteUrl) and h(productId) toget
    16 byte unique string.
    Sorry but you can't! Since the hashes will not be
    unique the combination will not be unique.There should be such hash function somewhere but I haven't found it. The definition is here http://www.x5.net/faqs/crypto/q94.html.

  • Limitations of public string declarations

    Is there anylimit for declaring number of public string in a java file.
    I have declared some 3300 Public String in a .java file as shown below
    public class JbnIntlLabel implements Serializable {
    public Properties prop = new Properties();
    //start of new 2 series labels
    public String Text_2A= null;
    public String securityname_2A = null;
    public String eqtTool_2A = null;
    3300 such declarations.
    once i try to create a extra string and trying to compile..,its giving the below error
    /devusr8/web61/WebLogicServer/weblogic61/config/NewWeb61Domain/applications/demo/WEB
    -INF/src/com/apollo/services/bean > demo.sh JbnIntlLabel.java
    An exception has occurred in the compiler (1.3.1-rc2). Please file a bug at the Java Devel
    oper Connection (http://java.sun.com/cgi-bin/bugreport.cgi). Include your program and the
    following diagnostic in your report. Thank you.
    java.lang.StackOverflowError
    at com.sun.tools.javac.v8.code.ClassWriter.writeFields(ClassWriter.java:588)
    at
    Can anybody help me out..
    Thanks and regards
    vijay
    Tata Consultancy Services.
    Mumbai -India

    Is there anylimit for declaring number of public
    string in a java file.
    I have declared some 3300 Public String in a .java
    file as shown below
    public class JbnIntlLabel implements Serializable {
    public Properties prop = new Properties();
    //start of new 2 series labels
    public String Text_2A= null;
    public String securityname_2A = null;
    public String eqtTool_2A = null;
    3300 such declarations.
    once i try to create a extra string and trying to
    compile..,its giving the below errorThese are member variables.
    The Java language (Java Language Specification) does not limit them.
    The JVM however does (Java Vitual Machine Specification.) However you are no where close to that limit.
    (Note that I do not consider this a great design. Unless you have profiled this under load I would simply keep the values in a hash table and use a named argument to retrieve each value.)
    >
    /devusr8/web61/WebLogicServer/weblogic61/config/NewWeb6
    Domain/applications/demo/WEB
    -INF/src/com/apollo/services/bean > demo.sh
    JbnIntlLabel.java
    An exception has occurred in the compiler (1.3.1-rc2).
    Please file a bug at the Java Devel
    oper Connection
    (http://java.sun.com/cgi-bin/bugreport.cgi). Include
    your program and the
    following diagnostic in your report. Thank you.
    java.lang.StackOverflowError
    at
    com.sun.tools.javac.v8.code.ClassWriter.writeFields(Cla
    sWriter.java:588)As pointed out this is a compile time error. When you deploy something to a container it needs to create wrappers to support it.
    So it compiles code. And the compiler is most likely written in java. So I would guess that your container server needs to have its stack space increased. This might be the server itself or it might be a property within the server depending on how it actually works. (And I have no idea which it would be.)

  • String length limitation on setString() in prepared statement

    Hi,
    Is any body aware of the length of string that can be passed to setString() method of prepared statement. I am getting an error "Data size bigger than max size for this type" if the string length is more than 2000 chars. I am using jdk 1.2.2 for running the application.
    Thanks in advance.
    Nihar.

    Please use the following method. It worked for me.
    PreparedStatement pstmt = ......;
    String str = .....;
    pstmt.setObject(index,str,java.sql.Types.LONGVARCHAR);
    Ranjan.

Maybe you are looking for

  • A problem in downloading a DRM pdf file.

    Hi, Today I purchased an ebook via Kobo's site: http://www.kobobooks.com/ebook/Applied-Natural-Language-Processing-Identification/book-dR0 XnmDKKk27gMjojat8DQ/page1.html It is in my library and when I go to ADOBE DRM PDF in order to download it and r

  • ATV2 With Viewing Preferences?

    We've been noticing some strange behavior in our ATV2/TiVo/SONY Bravia setup lately and we're hoping someone here can explain it. Movies stored on our server are sometimes running when we start up Apple TV. Titles neither of us went near are showing

  • Switching between 2 iphoto libraries...

    I went to the genius bar & they made me 2 iphoto libraries so I could keep my new and old photos separate and it was meant to be quite simple to be able to switch between the 2 but I don't know how! Can anyone help?

  • REG : Communication between R3 systems and PDK applciations

    Hi All, I have created one APC in Ep7.0 where i am accessing RFC .I am able to fetch the details from the RFC.But we need to pass the parameters from front end to get the details from the RFC. Can anybody help me in this reagard that how to pass valu

  • Iphone needed to be re-registered

    Last night I turned the power off on my iphone 3g. When I turned it back on there was a picture of a usb connector alternating with a phone keypad saying emergency calls only in different languages. I sync'd it up to itunes and all was fine. Why woul