Looping assistance (counting number of characters in a variable)

Good morning, all! I was wondering if anybody could take a look at this small, easy project I was working on today. I've searched the net for an answer and while it was useful and I learned a few things, nothing is really working. The code is pretty self explanatory, infact, I'm embarrassed I do not know how to do this, because I'm sure I know. Basically, counting the length of the variable is not working. The output is supposed to be as many times as the input is long in characters (I hope that makes sense!) Anyways, if you could take a look and tell me if you see anyway I could fix this, I would appreciate it.
import java.util.*;
import javax.swing.JOptionPane;/**
* @author Willaim
public class Loop {
     * @param args
     public static void main(String[] args) {
          String loopInput;
          int count;
          loopInput = JOptionPane.showInputDialog("Please enter a word for the loop demo: ");
          while(count < loopInput.length){
               System.out.println("" +loopInput);
               count = count + 1;
          for (count = -1; count < loopInput.length; ++count){
                    System.out.println(loopInput);
          do {System.out.println("loopInput");
               count++;
               }while (count < loopInput.length);
     }

1) to get length from a String, you must use a method and all methods end in parenthesis (arrays are different in that you are getting the length field, and this doesn't require parenthesis.
2) You probably don't want to use this "count" variable. You will probably be better with a for loop here since the number of iterations through the loop is defined in advance.
Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
&#91;code]
  // your code block goes here.
  // note the differences between the tag at the top vs the bottom.
&#91;/code]or
{&#99;ode}
  // your code block goes here.
  // note here that the tags are the same.
{&#99;ode}

Similar Messages

  • Method to count number of characters in a string?

    hi.
    i'm trying to write some script that will count the number of characters in a string passed into a constructor and then compare it against another value to check whether the string passed in is valid.
    something like this
    public class Stringcheck
    public static int maxStringLength;
    public static double minSize;
    public static boolean testStringLength(String x)
    // Insert method for counting number of chars in String x and name as 'int numberOfChars
    if(number of Chars <= maxStringLength )
    return true;
    else
    return false;
    can someone help me with writing this script.
    Thanks
    Richard.

    ummm, you dont need anything fancy. try:
    String test = "this is the test string";
    int length = test.length();

  • Count number of Characters in CLOB field

    Hi all,
    I posted this on another database, but I think it really belongs here. I have a CLOB field that stores reports in HTML markup languate. Here's an example of a report.
    <br><br></title> </head> <body contenteditable="true" text="#000000" bgcolor="#ffffff"> this is a test for a bilateral modifier </body> </html><br><br>
    I'm trying to provide a query that counts the number of characters that is not a HTML tag nor whitespace. I've attempted to use a combination of the length and replace function which first replace all HTML tags and whitespaces with nothing and then uses length to calculate the number of characters. Here's what the function looks like.
    <br><br>length(trim (both ' ' from replace (replace (replace(replace (replace(replace(replace(replace (replace(replace(replace (replace(replace (replace(reports.report_text ,'</head>',''),'</title>',''),'<body contenteditable="true" text="#000000" bgcolor="#ffffff">',''),'</body>',''),'</html>',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'',''),'>','')))
    <br><br>
    For the example above, the number of characters counted in the outputs is 66, which is clearly incorrect. I need to only count these characters for the example above "thisisatestforabilateralmodifier", but there is still white space that remains after I do the sequence of replaces. If someone can help, it's be greatly appreciated. Thanks.
    Message was edited by:
    user577468

    If you can convert your html string to valid xml you can do the following:
    michaels>  SELECT str, LENGTH(REPLACE(REPLACE(XMLTYPE (str).EXTRACT ('//text()').getclobval(),CHR(10)),' ')) length
      FROM (SELECT
    '<html>
    <head>
      <title></title>
    </head>
    <body contenteditable="true" text="#000000" bgcolor="#ffffff">
       this is a test for a bilateral modifier
    </body>
    </html>' str FROM DUAL)
    STR                                                                        LENGTH
    <html>                                                                         32
    <head>                                                                         
      <title></title>                                                               
    </head>                                                                        
    <body contenteditable="true" text="#000000" bgcolor="#ffffff">                 
       this is a test for a bilateral modifier                                      
    </body>                                                                        
    </html>                                                                          Otherwise regex_replace would be an alternative (on 10g).

  • How to count number of characters in a string?

    Hi
    I need to display values in a script. but the alignment getting distrubed if it is less than 20 charaters, for exmple material descirption is only displaying 20 characters in script. if it is less than 20 charcters the alignment getting changed.
    please help me ...urgent..
    thanks in advance...

    solution to this problem in script is not to count the characters but to align them based on positions .
    1.
    Use the tab positions  for that paragraph format to display the values in a finite format .
    In this u need to give the position start and position end length and use the same in the script as
    p ,,&itab-f1&
    say my value has to print from position 125mm to 155 mm
    i take one tab position for this paragraph format P and maintain the same in the output.
    here ,, is the tab position .
    See whether it is one character or 20 character it has to behave the same way it should not be misaligned .
    check the tab position for that paragraph format in Tabs ..
    regards,
    vijay.

  • Count number of characters in a string

    Another one for you experts:
    Is there a way to count the number of "-" in the strings below:
    For instance:
    1133500-1-RTN-629-RHR
    1133541-10-SRTN-F-630-LR
    Should return:
    4
    5
    respectively.
    Any ideas?
    Thanks in advance,
    Zack H.

    stringvar x := '1133541-10-SRTN-F-630-LR';
    stringvar array z := split(x,'-');
    ubound(z)-1;

  • Counting number of characters in a textbox

    I am keen to no, what is the best way to specify a number below a textarea, which countsdown each character entered till it reaches 0 then the user cannot enter any more characters?
    Thanks,
    Steve

    Look at some of these
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22public+void+insertstring%22+%2B%22extends+jtextfield%22+%2Bmaximum&col=javaforums

  • How to count the number of characters

    Dear All,
                Can anyone tell me a Function Code or sample code to count the number of charactes in a text.
    Regards,
    Vijay

    hi
    <b>use the inbuilt function strlen</b>
    Number of characters in arg; blanks at the end of data objects with a fixed length are not counted, although they are counted in type string data objects. If you use a non-Unicode double-byte code, a character that occupies 2 bytes is counted twice.
    <b>example</b>
    data: v_len type i,
    v_str type string value 'gggugik'.
    v_len = strlen( v_str ).
    write:/ v_len.
    Regards,
    ravish
    <b>plz reward points if helpful</b>

  • Counting the number of characters entered into a page item

    Is there a way to count the number of characters that are entered into a page item. I've got a field that can contain up to 20 characters. If 20 are entered I can do a = on my search, if less than that, then I have to do a wildcard search. I currently do a substr on the field to see if position 21 is null and position 20 is not null, then I have a 20 character field. Is there a more efficient way to do this and also is there a way to actually show the character count as the page item is being populated

    Hello user8014695 (name please),
    Try coding the select for your search as
    select ...
    from some_table
    where some_field like case when length(trim(:YOUR_ITEM)) = 20 then :YOUR_ITEM else :YOUR_ITEM || '%' end
    Note - I included the trim() assuming blank characters before or after shouldn't count.
    To show the character count as the item is being keyed-in, Google "javascript character count" for lots of ways to do this. To work these solutions into ApEx, check the ApEx help/documentation for incorporating JavaScript into your application - specifically the references on accessing page items using JavaScript.
    Hope this helps,
    John

  • How to Count Number of completed line items in past 6 months / 12 months ?

    How to Count Number of completed line items in past 6 months / 12 months ?
    Hi,
    I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
    Purchase Order document = ZEBELN
    Line Item = ZEBELP.
    I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
    I have "Delivery Completed" field, ELIKZ.
    So, based on this would I be able to calculate it in Query Designer?
    If so, Please let me know how

    Hello Deva
    If youe want to calculate the completed line item for last 6 or 12 month then i think u will be displaying the query data for these montrhs...create a customer exit to give you date range and restric it in filter area....
    Now Choose any of the below option
    1. I would suggest to implement an additional key figure "counter" in cube and fill values with one for which delivery is completed.
    Now use calculated key figure in Query Designer based on logic
    IF counter = 1 THEN counter ELSE 0
    OR
    2. create a formula variable based on ELIKZ and use replacement path variable, it will display you no. of docs for which delivery is completed....
    Award points if it solves your problem
    Revert back in case of further assistance...
    Thanks
    Tripple k

  • How to Count number of words in a file....

    Hi Experts,
    I have uploaded the text file, from the application server, like this: 
    call function 'GUI_UPLOAD'
      exporting
        filename = LV_ip_FILENAME
      tables
        data_tab = LT_FILETABLE.
    The text file contains some number character words....  like "sap labs india..... "
    Now, I wanted to count number of words in an internal table  LT_FILETABLE....  can anybody help me?

    Hi,
    Special Characters in Regular Expressions
    The following tables summarize the special characters in regular expressions:
    Escape character
    Special character Meaning
    Escape character for special characters
    Special character for single character strings
    Special character Meaning
    . Placeholder for any single character
    C Placeholder for any single character
    d Placeholder for any single digit
    D Placeholder for any character other than a digit
    l Placeholder for any lower-case letter
    L Placeholder for any character other than a lower-case letter
    s Placeholder for a blank character
    S Placeholder for any character other than a blank character
    u Placeholder for any upper-case letter
    U Placeholder for any character other than an upper-case letter
    w Placeholder for any alphanumeric character including _
    W Placeholder for any non-alphanumeric character except for _
    [ ] Definition of a value set for single characters
    [^ ] Negation of a value set for single characters
    [ - ] Definition of a range in a value set for single characters
    [ [:alnum:] ] Description of all alphanumeric characters in a value set
    [ [:alpha:] ] Description of all letters in a value set
    [ [:blank:] ] Description for blank characters and horizontal tabulators in a value set
    [ [:cntrl:] ] Description of all control characters in a value set
    [ [:digit:] ] Description of all digits in a value set
    [ [:graph:] ] Description of all graphic special characters in a value set
    [ [:lower:] ] Description of all lower-case letters in a value set
    [ [:print:] ] Description of all displayable characters in a value set
    [ [:punct:] ] Description of all punctuation characters in a value set
    [ [:space:] ] Description of all blank characters, tabulators, and carriage feeds in a value set
    [ [:unicode:] ] Description of all Unicode characters in a value set with a code larger than 255
    [ [:upper:] ] Description of all upper-case letters in a value set
    [ [:word:] ] Description of all alphanumeric characters in a value set, including _
    [ [:xdigit:] ] Description of all hexadecimal digits in a value set
    a f
          v Diverse platform-specific control characters
    [..] Reserved for later enhancements
    [==] Reserved for later enhancements
    u2192 More
    Special characters for character string patterns
    Special character Meaning
    Concatenation of n single characters
    {n,m} Concatenation of at least n and a maximum of m single characters
    {n,m}? Reserved for later enhancements
    ? One or no single characters
    Concatenation of any number of single characters including 'no characters'
    *? Reserved for later enhancements
    + Concatenation of any number of single characters excluding 'no characters'
    +? Reserved for later enhancements
    | Linking of two alternative expressions
    ( ) Definition of subgroups with registration
    (?: ) Definition of subgroups without registration
    1, 2, 3 ... Placeholder for the register of subgroups
    Q ... E Definition of a string of literal characters
    (? ... ) Reserved for later enhancements
    for more details please refer the following,
    [http://help.sap.com/abapdocu_70/en/ABENREGEX_SYNTAX_SIGNS.htm]
    [http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/902ce392-dfce-2d10-4ba9-b4f777843182?QuickLink=index&overridelayout=true]
    Thanks,
    Renuka S.

  • How to count number of raw & put result top of page?

    I try to count number of table raw it work fine  but when I wont to put result top of page it dose not work
    only count one table raw
    REPORT  ZTEST.
    DATA: it_sflight TYPE TABLE OF Sflight WITH HEADER LINE  .
    DATA counter TYPE i VALUE 0.
    start-of-SELECTION.
    SELECT-OPTIONS: carID for it_sflight-carrid.
    SELECT-OPTIONS: connID for it_sflight-connid.
    SELECT * FROM Sflight INTO CORRESPONDING FIELDS OF TABLE it_sflight 
    WHERE carrid IN carID and connID IN connid.
    loop at it_sflight .
      counter = counter + 1 .
      write: /5 it_sflight-carrid,sy-vline,
               30 it_sflight-connid,sy-vline,
                  45 it_sflight-fldate,sy-vline,
                    60 it_sflight-currency,sy-vline.
    ULINE.
    endloop.
    end-of-SELECTION.
    TOP-OF-PAGE .
    *START-OF-SELECTION.
    WRITE:  'Total Rows : ', counter.
    ULINE.
    WRITE: /5 'Carrid',sy-vline,
            30 'Connid',sy-vline,
            45 'Fldate',sy-vline,
              60 'Currency',sy-vline.
    ULINE.
    how can I solve this problem ?

    Hi
    Instead of using counter in a loop use describe statement.
    Describe it_sflight.
    the no of rows will get populated in the system variable sy-tfill.
    DATA: it_sflight TYPE TABLE OF Sflight WITH HEADER LINE  .
    DATA counter TYPE i VALUE 0.
    start-of-SELECTION.
    SELECT-OPTIONS: carID for it_sflight-carrid.
    SELECT-OPTIONS: connID for it_sflight-connid.
    SELECT * FROM Sflight INTO CORRESPONDING FIELDS OF TABLE it_sflight
    WHERE carrid IN carID and connID IN connid.
    DESCRIBE TABLE it_sflight.
    loop at it_sflight .
      counter = counter + 1 .
      write: /5 it_sflight-carrid,sy-vline,
               30 it_sflight-connid,sy-vline,
                  45 it_sflight-fldate,sy-vline,
                    60 it_sflight-currency,sy-vline.
    ULINE.
    endloop.
    end-of-SELECTION.
    TOP-OF-PAGE .
    *START-OF-SELECTION.
    WRITE:  'Total Rows : ', sy-tfill.
    ULINE.
    WRITE: /5 'Carrid',sy-vline,
            30 'Connid',sy-vline,
            45 'Fldate',sy-vline,
              60 'Currency',sy-vline.
    ULINE.
    Thanks
    Rahul jain
    Edited by: Rahuljn on Feb 2, 2011 10:58 AM

  • How do I find the number of characters including spaces in Pages '13?

    Hi,
    I need the number of characters including spaces on the new pages for an online document I have to fill in. I've found the character count excluding spaces but this is of no use to me.
    Thanks

    http://lifehacker.com/5907637/add-a-right+click-option-to-count-characters-words -and-paragraphs-in-any-mac-program
    Use this version of the script:
    http://hints.macworld.com/comment.php?mode=view&cid=129016
    Peter

  • URGENT HELP NEEDED: counting number of particles from image

    this image on the left is showing particles
    hello i want to create a small VI that can count number of particles from a image that i load up. please see the attached image of particles and the VI printshot.
    I have used the tutorial "counting number of particles" but still the above VI does not work. it shows the number of particles = 1.. I do not know why it is doing so??
    I am not an expert in Labview so please can someone tell me where the problem is. sorry i could not attach the VI file itself but i have given an image of it..
    after anyone has solved this problem, i have to create a live system that will get live images from the camera - four frames every sec and the above VI has to count the
    number of particles for each frame and output to the user?? is this possible can anyone do it for me???
    p.s. in the above VI i read the image from file and count the number of particles. i do not do it to the binary image becuase the binary image is only a black screen
    when i run it
    thankyou

    Hi Farhan,
    Vision Assistant would be the best option to create some steps which you can then export to LabVIEW. You should try using the IMAQ Find Circles.vi. The attached image helps you find the number of circles of an image acquired from a camera. I have used the IMAQdx VIs in this example.
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies
    Attachments:
    vision.vi ‏59 KB

  • Limit on the number of characters of the Input file of Input Agent

    HI
    I am working on the Input Agent of one of my IPM applicaton. I just want to know what would be the limit on the number of characters in the input file of input agent. That means that what should be the total count limit of the characters of the Input file of the Input Agent, so that IPM Efficiently process the Input file.
    Thanks & Regards
    Chandan Kumar
    SYSTIME, India

    Thank you t quinn for your reply as I do really appreciate the help.
    I don't quite understand what your suggestion was and before I try to figure it out and play around with numbers, I thought I should clarify further. When i wrote I want to paste the content into the cell and have it limited to 100 characters I was mis-spoken. I actually have all the content already in the columns in a spreadsheet and would now like to just limit some of the columns to hold only 100 characters in a cell so that when its a CSV file it will be accepted to the program I'm trying to upload it to.
    SO does that change the way you can answer my question?
    Is there a way to just limit the content currently in a spreadsheet to 100 characters per cell?
    Kindly

  • Count number of records in a internal table

    hi
    i want to count number of records in internal table
    pls let me know how to count the number of records in a internal table.
    regards
    Arora

    hi
    one way is
    data field type i.
    Decribe table itab lines field.
    write: / field.
    displays the no of records in tha internal table
    or if u want to write logic.
    data:
      w_count type i.
    loop at itab.
    w_count = w_count + 1.
    endloop.
    write: / w_count.
    displays the no of records.
    reward points if useful.

Maybe you are looking for

  • How to print a Barcode VERTICALLY in a SAP Script ?

    Dear Experts.. I have to print a Barcode <b>vertically</b> in a SAP Script. Could you please help me regarding this. Thanks in advance.

  • Getting an arrayindexoutofbounds error when trying to run mail app

    here is the code, it compiles fine, but when i run it, i get an array index out of bunds error import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SimpleSender {   public static void main (String args[]) throw

  • How to make javascript submit a button instead a form

    Hi , I plan to do a popup box using javascript when user click on Yes , it will actually submit a button which actually submit a form because i want the action behind / binding to that button to be invoked. if i submit a form only.. i think the metho

  • HT1918 Re set security questions

    How do I re set my security questions for my Apple ID account as I cannot remember the answers

  • Sort in slideshow

    I have iphoto 8 and have an event of photos I want in a slide show. Unfortunately the order is reversed. There are 154 photos. I have re-named the photos to re-sort them but when I add them to slideshow they revert to there original order based on ti