How to count no. of tokens in a string?

hello everybody?
I am using StringToknizer to read a csv file line by line.
My problem is:
i want to know how many tokens are there in a particular row. How to count it at a streatch?
i am using
<%
if (st.hasMoreTokens())
     a3=st.nextToken().trim();
%>i thought of using String.split(), but, i don't know how to use it?(what class to import)
Anyguidence will be appreciated
Thanks for your time.
Regards,
Ashvini

StringTokenizer will do it for you!
int numberOfTokens = st.countTokens();m

Similar Messages

  • How do count the character in the given string?

    hi all,
    i have astring like 'AAAARAMARAOAAA'.
    i want count how many 'A's in this string using sql statement.

    Is that a joke? You asked that in a previous thread of yours: how do count how many 'A' s in this string using sql stmt?.
    C.

  • How to count number of words in a string?

    Is it only possible by counting the number of white spaces appearing in the string?

    Of course that also depends upon how accurate you need to be and what the string contains. It is completely possible that there might be a line break which doesn't have a trailing or leading space.
    Like that.
    In that case Flash's representation of the string is likely "...space.\n\nLike that.." In chich case "space.\n\nLike" will be a word.
    Also if you split on space and there are places where there are two spaces in a row you could inflate your number. So somthing that changes newlines (and returns) to spaces, then removes any multiple spaces in a row, and finally does the split/count thing would be more accurate.
    But it all depends upon what you need.

  • 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.

  • How to count the number of times a string occurs in a column.

    I am listing team names in a column and want to have a tally at the bottom. In Excel I can use =SUM(IF(range="text",1,0)), but Numbers will not accept a range in that IF statement. ANy suggestions on a formula for his? I know I could create hidden columns and put formulas in all those and hen count them, but that sure seems like a heard way to resolve what should be one formula.
    THanks!

    Those which took time to read carefully *_iWork Formulas and Functions User Guide_* are aware of the availability of wildcard characters.
    =COUNTIFI(range;"=text")
    will do the trick.
    Yvan KOENIG (VALLAURIS, France) lundi 26 avril 2010 17:36:34

  • Scanner -- how to count spaces a part of a string

    I'm fooling around with Scanner in a little program just to teach myself. Right now, when given the chance to enter data, anything after a space is ignored, so, for example, if one enters "John Smith" for a name entry, on printout it only says "John." How can I fix this?

    Melanie_Green wrote:
    Opps forgot to close the scannerUmmm... As a general rule of thumb... If you open it, close it... and conversely: If you didn't open it, don't close it... any other way lies madness, like having to check if the stream has been closed by something else before every write. Yeck!
    System.in, out, and err are opened and closed for you automatically... so you shouldn't (IMHO) close a scanner on System.in, because it would close the underlying System.in stream... which probably isn't what you wanted to do anyway.
    And (just my humble opinion) I'd regard that "input loop" as "an abuse of loops"... because it's more complicated than it needs to be. However...
    If one where to delegate the "simple attributes" of a "bean-like" class to a Map... Hmmm... the below code concept still isn't (IMHO) actually useful for real apps, because it's limited to String attributes only, but it was an interesting learning exercise none-the-less... and one could conceivably extend it to support all the primitive types, but what's the point... then you may as well just write simple old beans, forget about all the "clever stuff" under the hood, and get on with what the real problems ;-)
    package forums;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Scanner;
    * A base class for simple Data Transfer Objects with only String attributes.
    abstract class DTO
      private static final Scanner SCANNER = new Scanner(System.in);
      protected final String CLASS_NAME;
      private final String[] ATTRIBUTE_NAMES;
      private final String PROMPT_FORMAT;
      private Map<String, String> attributes = new HashMap<String, String>();
      public DTO(String[] attributeNames) {
        this.CLASS_NAME = getClassNameOnly(this.getClass());
        this.ATTRIBUTE_NAMES = attributeNames;
        this.PROMPT_FORMAT = "    %-"+maxLengthOf(attributeNames)+"s : ";
      public void enterAttributes() {
        System.out.println("Please enter the attributes for "+CLASS_NAME+" : ");
        for (String attributeName : ATTRIBUTE_NAMES) {
          String prompt = String.format(PROMPT_FORMAT,attributeName);
          String attributeValue = read(prompt);
          attributes.put(attributeName, attributeValue);
      @Override
      public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("<").append(CLASS_NAME).append(">\n");
        for (Map.Entry<String,String> attr : attributes.entrySet()) {
          result.append("<").append(attr.getKey()).append(">");
          result.append(attr.getValue());
          result.append("</").append(attr.getKey()).append(">\n");
        result.append("</").append(CLASS_NAME).append(">\n");
        return result.toString();
      // ========== HELPER METHODS ==========
      // NOTE: in a real system these would be in various Utilz classes.
      // read from krc.utilz.io.Conzole
      private static String read(String prompt) {
        System.out.print(prompt);
        return SCANNER.nextLine().trim();
      // read from krc.utilz.Clazz
      private static String getClassNameOnly(Class clazz) {
        String fullName = clazz.getName();
        return fullName.substring(fullName.lastIndexOf('.')+1);
      // read from krc.utilz.Stringz
      private static int maxLengthOf(String[] names) {
        int max = names[0].length();
        for(int i=1; i<names.length; i++) {
          max = Math.max(max, names.length());
    return max;
    * A Person object
    class Person extends DTO
    private static final String[] ATTRIBUTE_NAMES = {
    "FirstName", "LastName", "Street", "State"
    public Person() {
    super(ATTRIBUTE_NAMES);
    public class PersonDatabase3
    public static void main (String[] args) {
    try {
    Person person = new Person();
    person.enterAttributes();
    System.out.println(person);
    } catch (Exception e) {
    e.printStackTrace();
    Cheers all. Keith.
    Edited by: corlettk on 21/06/2009 16:47 ~~ Clearer.

  • How to count number of vowels in the String?

    Write a program that calculates the total number of vowels contained in the String" Event Handlers is dedicated to making your event a most memorable one."
    Please help!

    http://leepoint.net/notes/javanotes/40other/20examples/60Strings/example_countVowels.html

  • How to Look at current Token

    When using the tokenizer in Java I see that you can count tokens "countTokens() " , see if a string has more tokens "hasMoreTokens()", etc. But how do you work with the current token?
    For example:
    while ((str = in.readLine()) != null )
         StringTokenizer tokens = new StringTokenizer(str);
         while (tokens.hasMoreTokens())
              System.out.println( tokens.nextToken() + "\n" );
              //tokenStr = tokens.nextToken();
              count++;
              //if (tokenStr.equals("<body>"))
              //     bodycount++;
             }I can count all the tokens in the string but how can I count the tokens "<body>"?
    Any help please
    eddiemjm

    You are almost there. Trywhile ((str = in.readLine()) != null )
         StringTokenizer tokens = new StringTokenizer(str);
         while (tokens.hasMoreTokens())
              tokenStr = tokens.nextToken();
              System.out.println( tokenStr + "\n" );
              count++;
              if (tokenStr.equals("<body>"))
                   bodycount++;
             }Note the change and move of the println() call.

  • How do I deal with Tokenized strings that are blank?

    I'm writing a little application that writes data to a file. It sends data to the file as a "|" delineated string. Then I use tokenizer to break up the string as follows:
    try {
                                  String searchtext = SearchTxt.getText();
                                  String tokenString = "";
                                  String[] returnData = new String[8];
                                  File filedata = new File("bigbase.txt");
                                  BufferedReader in = new BufferedReader(
                                  new FileReader(filedata));
                                  String line = in.readLine();
                                  while ( line != null) {
                                  Pattern pat = Pattern.compile(searchtext);
                                  Matcher mat = pat.matcher(line);
                                       if ( mat.find() ) {
                                       StringTokenizer t = new StringTokenizer(line, "|");
                                       maintextArea.setText("");
                                       int count = 0;
                                            while (t.hasMoreTokens()) {
                                                 tokenString = t.nextToken();
                                                 returnData[count] = tokenString;
                                                 maintextArea.append(tokenString + " ");
                                                 System.out.println(tokenString);
    etc etc etc
    The problem is that when the tokens are blank, I get an endless loop when I try to print out the data on that last line. How do I deal with Tokens that are blank so they don't endlessly loop my output?
    Thanks
    MrThis

    Most people would probably tell you to use:
    String.split(...);
    But I'm not most people and I wrote this class before regex support was added to the String class which is based on StringTokenizer but supports empty tokens:
    http://www.discoverteenergy.com/files/SimpleTokenizer.java

  • How to pass credentials/saml token access sharepoint web service ex:lists.asmx when sharepoint has single sign on with claims based authentication

    How to pass credentials/saml token exchange to the sharepoint web service ex:lists.asmx when sharepoint has single sign on with claims based authentication 
    Identity provider here is Oracle identity provider 
    harika kakkireni

    Hi,
    The following materials for your reference:
    Consuming List.asmx on a claims based sharepoint site
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/f965c1ee-4017-4066-ad0f-a4f56cd0e8da/consuming-listasmx-on-a-claims-based-sharepoint-site?forum=sharepointcustomizationprevious
    Sharepoint Claims based authentication and Single Sign on
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/2dfc1fdc-abc0-4fad-a414-302f52c1178b/sharepoint-claims-based-authentication-and-single-sign-on?forum=sharepointadminprevious
    Sharepoint Claim Based Authentication Web Service issuehttp://social.msdn.microsoft.com/Forums/office/en-US/dd4cc581-863c-439f-938f-948809dd18db/sharepoint-claim-based-authentication-web-service-issue?forum=sharepointgeneralprevious
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How to get the device token in windows phone 8 sliverlight application?

    Hi,
    I am developing a windows phone 8 silverlight application . For my application I want to add push notification service , for this service I have to call one web service in my app . This api requires device token , device id ..etc , I am able to get the all
    the things except devicetoken .
    How to get the device token of a device ?
    any help?
    Thanks...
    Suresh.M

    Most probably device token is the push channel url which is returned by MPNS when a request is made to it.
    Step 3 here: Push notifications for Windows Phone 8
    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

  • How to count number of sales orders generated in a month in SAP SD

    Hi SD Gurus,
    I have a very strange query from client. I have to count the number of sales order created in a month for a z report. For example 30 in Jan, 25 in Feb etc. Could anyone suggest me How to count number of sales orders generated in a month in SAP SD.
    Regards
    Vinod Kumar

    Hi,
    Goto the T.Code "SE16" or "SE16n" or "SE11".
    Enter the table name as VBAK
    Enter the created on date as the starting date of the period and to date as the end date.
    Enter.
    Click on "Number of Entries".It will tell you the number of entries created in a particular period.
    If you want a report,goto the T.Code "VA05n".
    Regards,
    Krishna.

  • 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 related radibuttons in the doccument?

    The field "radiobutton" can have several related radiobuttons.
    How to count quantity of radibuttons with the same name in the doccument?

    With
    this.getField("radiobutton.0");
    this.getField("radiobutton.1");
    and so on you can access the different instances.

  • How to count number of repeated characters in a String

    I have a String.... 10022002202222.
    I need to know how many 2's are there in the string... here the string contains eight 2's..
    Thanks in advance..

    it is workingYes, but... attention to surprises...
    SQL> var v1 varchar2(1000);
    SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
                                       6
    SQL> exec :v1 := 'cccccc';
    PL/SQL procedure successfully completed.
    SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
    LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
    SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
    LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
                                              6
    SQL>

Maybe you are looking for

  • How to reset numbers in real time display in Cisco Supervisor Desktop?

    Hi all, I wonder about numbers in real time display in Cisco Supervisor Desktop. There are many statistic number for example : Call Handled, Max Talking, Avg Talking, Max Ready, Total Ready, Call abandoned, etc. Is there any way to reset those number

  • Mini-DisplayPort to HDMI adapter not coming soon

    Despite what has appeared in various blogs around the web (and what I had been told previously), it looks like a Mini-DisplayPort to HDMI adapter from Monoprice will not be arriving this month. An e-mail message from monoprice tech support states: "W

  • Printer on network shared between PC and Mac

    Thanks to this forum I managed to establish an Airport Extreme network with: Airport Extreme Base station, Netgear router with 4 ethernet hub, iBook G4 (connecting through Airport) iMac G5 (connecting through ethernet! because the signal is too low i

  • Purchase requisition replication problem

    Hi ,                 I am using SRM 7.0 with backend ECC EHP4 but I have defined EHP3 in u201C Defined System Landscapeu201D. I am creating Purchase requisition in ECC and it is replicating in SRM but I am not able to see in shopping cart whereas I c

  • Terms of payment/cheque post date issue

    Hi guys. On PO and MIRO terms of payment PD15 is being used. How can I make the cheque date post dated. Baseline date March 18 Due date April 2 On F-58. I want the cheque date to be April 2 without opening the next period. Is it possible at all? Can