Parse string by length

I have a incoming data string that is Hex, which is comprised of messages that have a string length of 98 characters (no delimiters).  How do I got about parsign this these strings?  I've tried to use something like a match regular expression, or a scan from string, inside a while loop.  Offsetting the incoming string by 98 characters, trying to read a formatted string (%98s), then building an array of the found messages, until I have reached the end of the string.  But I am unable to get this approach to work properly.

How about a loop that spits the string at the 98th character.  This attached picture shows a loop that will create an array of strings with each element (except possibly the last one) is 98 elements in size.
Message Edited by paulmw on 10-20-2006 12:51 PM
Attachments:
stringArray.JPG ‏10 KB

Similar Messages

  • Parse String inside PL/SQL

    What is the easiest way to parse a variable length string, containing x occurrences of data base fields (each occurrance separated
    by a delimeter) inside of a PL/SQL program.
    For example the string is: |x,y,z|x,y,z|
    Thank
    null

    The trick here is to count the number of items in the list(s). Use this code to determine the number of elements in a list:
    length('|x,y,z|x,y,z|') -
    length(replace('|x,y,z|x,y,z|','|')) - 1
    yields 2
    length('x,y,z') -
    length(replace('x,y,z',',')) + 1
    yields 3
    Note the +/- depends on the use of either a "fat" or "normal" list (i.e. delimiters at the front and back of list vs. just between elements).
    Once you know the number of elements, use substr to get the pieces. This works in plsql and sql so be creative; use a table with numbers in it if you want a solution that is sql only (my preference) as in:
    create table intgr (intgr number);
    insert into intgr values (1);
    insert into intgr values (2);
    insert into intgr values (999999...);
    select substr(...,instr(...,'|'),1,intgr.intgr ...
    from intgr
    where intgr =
    length(....)-length(....)+...
    think it through, I use this alot.
    a date table with dates from the last 300 and next 300 years works for lots of stuff too, be creative.
    create table somedates (adate date);
    Good luck.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Olga:
    What is the easiest way to parse a variable length string, containing x occurrences of data base fields (each occurrance separated
    by a delimeter) inside of a PL/SQL program.
    For example the string is: |x,y,z|x,y,z|
    Thank
    <HR></BLOCKQUOTE>
    null

  • Parsing String

    i have problem to parse string to document
    i have string like this str = "<root><data>1</data><data>2</data><root>";
    how to parse this string in docoment xml

    import java.io.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    public class PrettyPrinter {
       public static void main(String[] args) {
            // Assume filename argument
            String filename = args[0];
            try {
                // Build the document with SAX and Xerces, no validation
                SAXBuilder builder = new SAXBuilder();
                // Create the document
                Document doc = builder.build(new File(filename));
                // Output the document, use standard formatter
                XMLOutputter fmt = new XMLOutputter();
                fmt.output(doc, System.out);
            } catch (Exception e) {
                e.printStackTrace();
    }The above code is taken directly from
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom-p2.html
    u don't have to use Factories, this is what is said in that excerpt, it is very easy to use, and it is said that 80 % of the xml work can be done with 20 % or less work using JDOM.
    n joy ....
    </ksenji>

  • String with length 1 became 4 when nls_lang_semantics=CHAR

    Hi,
    We are using Oracle 9.2.0.1 database with charset = UTF-8, and we have set nls_lang_semantics=CHAR.
    We got a problem in our java program is that for a column with char(1), after I insert a java constant 'Y', the result I get back from select is a string of 'Y ', i.e. the string returned is not a string with length=1, but with length=4!! How can I correct the problem to get a string with length=1?
    Regards,
    Roy

    Hi,
    Thanks for the responses but I don't think you're quite right. Forms 6i should indeed work with Unicode as a database character set as long as it is UTF8 rather than AL32UTF8. This can be seen in various Metalink documents and also in the Release 6i Guidelines for Building Applications here (section 4.1.5):
    http://download-west.oracle.com/otn_hosted_doc/forms/forms/A73073_01.pdf
    The problems started when I changed NLS_LENGTH_SEMANTICS to CHAR. Its understandable if Forms 6i does not recognise this setting as it pre-dates it but I wanted to confirm this.
    We want to migrate our existing application to work with multibyte characters. Unfortunately there are table columns, PL/SQL variables etc. that are too small when defined as a length in bytes.
    I am looking for the least impact method to rectify this. On the server I can use NLS_LENGTH_SEMANTICS but if I can't get Forms to work with it then I may need to rethink.
    I realise that using Forms 9i or 10g would support the parameter but it is not possible to upgrade at the moment.
    Has anyone any other suggestions or methods for migrating an application to using multibyte characters?
    Thanks again,
    Kevin.

  • BAD parse error: zero-length content

    Hi there!
    Unfortunately I have a problem with JavaMail which I can not reproduce. Therefore, I don't have any 'debug' output of JavaMail. But maybe some of you have a clue for me. :)
    This is the error stack (just a snippet) which I get from JavaMail:
    javax.mail.MessagingException: A244 BAD parse error: zero-length content;
      nested exception is:
         com.sun.mail.iap.BadCommandException: A244 BAD parse error: zero-length content
         at com.sun.mail.imap.IMAPFolder.getMessagesByUID(IMAPFolder.java:1938)
         at org.zimbra.exchange.service.source.ExtendedEmailSyncSource.getMessagesByUID(ExtendedEmailSyncSource.java:1751)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: com.sun.mail.iap.BadCommandException: A244 BAD parse error: zero-length content
         at com.sun.mail.iap.Protocol.handleResult(Protocol.java:343)
         at com.sun.mail.imap.protocol.IMAPProtocol.fetchSequenceNumbers(IMAPProtocol.java:1284)
         at com.sun.mail.imap.IMAPFolder.getMessagesByUID(IMAPFolder.java:1920)
         ... 13 moreAnd this is my getMessagesByUID method:
         private Message[] getMessagesByUID(long[] uids, IMAPFolder f)
                   throws StoreClosedException {
              Message[] result = new Message[0];
              try {
                   result = f.getMessagesByUID(uids);
              } catch (StoreClosedException e) {
                   throw e;
              } catch (MessagingException e) {
                   log.trace("The messages could not be fetched from the server.",     e);
              } catch (Exception e) {
                   log.error("An unexpected error occurd. "
                                  + e.getClass().getSimpleName(), e);
              return (result);
         }My problem is that I can not reproduce the error and so I don't know why the error is thrown. According to the JavaDoc it should return a 'null' entry for messages where it can not find the UID.
    thanks for your help.

    The error message is coming from your IMAP server. It seems to be complaining about the
    message that JavaMail sent it. The getMessagesByUID method will send an IMAP FETCH
    command. That command doesn't include any variable length content, so I don't know what
    exactly the server could be complaining about.
    Perhaps your server has a log file that might have more information?
    Otherwise, you'll probably need to capture the debug output so that you can examine it later
    the next time this problem occurs.

  • What does this error means? "Line 20 column 57: character content of element "language" invalid; must be a string with length equal to 3 (actual length was 7) at XPath /package/book/metadata/languages/language" "

    Hi there.
    I am about to publish a book in English and Chinese.
    What does this error means?
    Line 20 column 57: character content of element "language" invalid; must be a string with length equal to 3 (actual length was 7) at XPath /package/book/metadata/languages/language"
    And where is line 20, column 57?
    Thanks folks!

    Go into iTunes Producer and select from the dropdown, don't type.
    cs
    iBooks Author Guide

  • How to parse string to date in j2me?

    How to parse string to date in j2me?
    Please help me.

    Hi..
    String dyStr = "20";
    String mtStr = "1";
    String yrStr = "1999";
    Calendar cal = Calendar.getIntstance();
    int dy = Integer.parseInt(dyStr);
    int mt = Integer.parseInt(mtStr);
    int yr = Integer.parseInt(yrStr);
    cal.set(Calendar.DATE, dy);
    cal.set(Calendar.MONTH, mt);
    cal.set(Calendar.YEAR, yr);
    OK?

  • How could i parse string and link its model with my files in eclipse project?

    How could i parse string and link its model with my files in eclipse project?, as i read that we dont have to use standalone mode while working with eclipse projects.
    Example of what i want to do:
    I have file1.dsl in my project which contains some statements but the declaration of these statements are not in another file, i need to put them only in my code

    Hi Stefan,
    I have eclipse project contains 2 files, file1.dsl and file2.dsl, you can see the contents of the files below.
    file1.dsl contains some statements as shown below and file2.dsl contains the declarations of the variables. (like in C++ or Java we have declarations and usage)
    At this step file1.dsl and file2.dsl will be parsed successfully without any errors.
    Lets imagine that we will delete this project and will create another one and the new project will contain only file1.dsl (which contains the usage)
    At this step this file (file1.dsl) will contains some errors after parsing it, because we are using variables without declarations.
    So what i need is to parse the content of file2.dsl directly without adding this file to the project.
    I need to add the content of file2.dsl directly as a string in the code and parse it. just like that ( "int a;int b;" )
    And link file1.dsl with the model generated after parsing my string
    file1.dsl
    a++;
    b++;
    file2.dsl
    int a;
    int b;
    Thanks

  • Trouble parsing string

    I need to parse strings in the format "City State
    Abbreviation Zipcode" (ie "Glenview, IL 60062") to seperate them as
    their own variables. Problem is that sometimes there is a comma
    after city, sometimes not, so I've resorted to REfind to seperate
    the string. Here's the snippet, "city" is the entire string I
    mentioned above. The problem is that the refind I use seems to be
    returning 0. I'm trying to find the two capital letters that
    designate the state abbeviation.
    <cfif city neq ''>
    <cfset crpos = refind("[:upper:][:upper:]",city) >
    <cfset zip = trim(right(city,len(city)-crpos))>
    <cfset citystate = trim(left(city,crpos)) >
    <cfset newpos = find("#chr(32)#",citystate) >
    <cfset state =
    trim(right(citystate,len(citystate)-newpos)) >
    <cfset actualcity =
    trim(left(citystate,len(citystate)-newPos)) >
    </cfif>

    I probably should mention some explaination about what the
    regular expression is doing:
    Note: Groups are RegExp statements surrounded by ()
    Group 1: Combination of Letters and Spaces (e.g. City Name)
    optional comma and (required) space
    Group 2: 2 Character upper case state code (State Code) (note
    - depending on your source, state codes may not always be upper
    case)
    (required) space
    Group 3: 5 digit string (e.g. Zip Code) (note - again,
    depending on your source, you may be getting 5 digit zip + 4 or
    even non-us zip codes that may involve alpha characters.)
    The replace function is using back references to refer to the
    text matched by group 1,2 and 3.

  • Split Function unable to parse string correctly

    Hi,
    I'm using split function to split string into multiple rows using comma "," as delimiter. In a string I have following values which are not parsed correctly as they have comma inside the values. 
    American Dawn, Inc.
    Battalian USA, Inc.
    Fria USA, Inc.
    Lazer, Inc.
    Mexilink Inc.
    Is there any other approach to fix this issue?
    Here is the split function Im using:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(MAX), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(MAX) NULL 
    As 
    Begin 
    Declare @item varchar(MAX), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final
    delimiter 
    Select @List = @List + @Delimiter -- get position of
    first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos
    -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List)
    - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    Another user in this forum posted a split function that
    he wrote:
    CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
    RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
    AS
    BEGIN
    WHILE CHARINDEX(@delim,@string) > 0
    BEGIN
    INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
    SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
    END
    INSERT INTO @result (value) VALUES (@string)
    RETURN
    END
    GO
    Both of them are unable to parse above values incorrectly.
    FYI:  String is made of values that are selected
    by user in SSRS report. I think SSRS when combine values , put comma "," between multiple values.
    Any help or guidance would be appreciated.
    ZK

    duplicate of
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/820ac53c-ce25-4cc7-b828-5875a21d459d/split-function-unable-to-parse-string-correctly-in-ssrs-report?forum=sqlreportingservices
    please dont cross post
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Hi to parse String "x;y:z" in Core Java

    hi to parse String "x;y:z" in Core Java

    Deepak_A_L wrote:
    how do i parse a String "X;Y:Z" in java i.e the results of parsing the string
    String s = "X;Y:Z"
    in terms of ENGLISH LANGUAGE -->(X Semicolon Y Colon Z)
    should be the below o/p individual Strings.
    X
    Y
    Z
    how do i get the above output.????Split on a semi- or regular colon using String's split(String regex) method.

  • Mastermind / Parse string with error handling ....

    Ok I am not going to hide the fact this looks like a homework question, honestly I already handed it in and now this is bothering me that I couldn't figure it out.......
    We had to make a mastermind client/server game only using text no graphical everything runs fine but how would one do error catching on this. (code posted below)
    Basically the user types in the command "guess r r r r" (guessing that the secret code is red four times ) and it parses it and assigns guess[] with the r and checks it based on the randomly generated color. The problem that I have is that is if someone makes a typo for example guess r rr r. How would one stop it from crashing from an out of bounds array request?
    if (command.matches("guess.*"))
                               int white = 0;
                               int black = 0;
                               String phrase = command;
                               String delims = "[ ]+";
                               String[] guess = { null, null, null, null, null, null, null };
                               guess = phrase.split(delims);
                               for (int i = 0; i < 4; i++)
                                    if (color.equalsIgnoreCase(guess[i+1]))
                             black++;
                        else if (color[i].equalsIgnoreCase(guess[i+1]))
                             white++;
                        else if (color[i].equalsIgnoreCase(guess[i+1]))
                             white++;
                        else if (color[i].equalsIgnoreCase(guess[i+1]))
                             white++;
                   if (black == 4)
                        anwser = "You WIN!!!!!!!! KIRBY DOES A SPECIAL DANCE FOR YOU \n (>'.')> (^'.'^) <('.'<) \n";
                        gamePlaying = false;
                        commandChecker = true;
                   else
                        turn++;
                        commandChecker = true;
                        anwser = "You got " + black + " black and " + white + " white it is your " + turn + " turn \n";
                   if (turn >= 10)
                        anwser = "You Lost =( , try again, the anwser was " + color[0] + color[1] + color[2] + color[3] + "\n";
                        gamePlaying = false;

    cotton.m wrote:
    if(guess.length!=4){
    // do something else besides evaluating the guesses. because something went wrong
    I should add that usually the best way of avoid array index out of bounds exceptions is to avoid ever hardcoding things like
    for(int i=0;i<4;i++)The 4 there is dangerous.
    It's safer to use the length
    for(int i=0;i<guess.length;i++)And the same applies to List(s) and the size method. Again usually that's a better idea but in your specific case anything more or less than 4 is not only a looping problem it would cause logical errors in the rest of your code... it is an exceptional case and should be dealt with specifically in your code.

  • Would like some help converting an array of strings into multiple parsed string arrays

    Hello everyone.
    this is a very novice question and I sincerely apologize for that, but i need some direction!
    i have an array of strings:
    (('J01',), ('0', '0', '0', '1'))
    (('J02',), ('0', '1', '0', '1'))
    (('J03',), ('0', '0', '0', '0'))
    ect...
    i would like to know what are some of the best ways to gain access to this information (aka, parse it). The field lengths are not static and all those ones and zeros could very possibly be two digits at times (0 = off state, 1-100 = on state), so simply pulling characters out of a given position of the string will not always work.
    what i would like to achieve is to make either separate arrays for each desirable element, eg:
    array one:
    J01
    J02
    J03
    array two:
    0
    0
    0
    array three:
    0
    1
    0
    and so on.
    or maybe even a matrix (if that’s feasible).
    other than that I am totally up for suggestions!!
    thank you very much,
    Grant.

    Assuming fixed structure (not necessarily length of the different numbers or names).

  • Trouble with Parsing String

    I am trying to take a string input from the command line and push it to an array then compare the array to another to see if there are any identical values. Here is the code in case it doesn't make sense.
    //  Parser.java
    //  PLCProject1
    //  Created by MilesB.
    //  Copyright 2007 . All rights reserved.
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class Parser {
    public static void main(String[] args)
              //Prompt the user to enter in String.
              System.out.println("Please enter in String to be tested");
              Scanner MyScan = new Scanner(System.in);
              String StringToTest = MyScan.next();
              char StringTestArray[] = new char[StringToTest.length()];
              int Array[] = {1,2, 3, 4, 5, 6, 7, 8, 9, 0};
              for(int j=0; j< StringToTest.length()-1; j++)
                        System.out.println(StringToTest + " ");
                        System.out.print(Array[j]);
              //open up standard input from CLI
              //BufferedReader ReadIn = new BufferedReader (new InputStreamReader(System.in));
              //StringToTest = ReadIn;
              //Testing the Entered String to see if it contains numeric values.
              for(int i=0; i< StringToTest.length()-1; i++)
                   for(int k=0; k< StringToTest.length()-1; k++)
                   if (StringTestArray[i] == Array[k])
                             System.out.println("This String contains numeric values");
                             break;
                   else
                   System.out.println("This Char is good");
                   System.out.println("This String was good");
    }

    ?

  • Parsing strings - baffling problem

    Hello, I have an issue with parsing tokenized strings that I am hoping someone can help me out on:
    I'm reading in a file which contains a line of the format n,n,n where n are integers (followed by other stuff.)
    I'm using the split() function to tokenize the string into an array of three strings.
    When I try to parse the strings to integers, I throw a NumberFormatException, but if I just read out the strings, they look fine.
    For example, if I read out the value of tokens[0] via System.out.println(tokens[0]), I get 1000, but ("1000"==tokens[0]) returns false;
    When try Integer.parseInt[tokens[0]), or:
    Integer.parseInt[tokens[0].trim())
    I get the exception, whereas:
    String tmp = "1000";
    Integer.parseInt[tmp) works fine.
    It seems that the two statements are identical. I'm kinda lost.
    Any pointers?
    Here is the code segment:
    {code}
         public boolean doOpen(String fName)
              File file = new File(fName);
         try
              String current ="";
              String delimiter = ",";
              BufferedReader br = new BufferedReader(new FileReader(file));
              current = br.readLine();
              if(current==null)
                   return false;
              else
                   System.out.println(current);
                   String[] tokens = current.split(delimiter);
                   if(tokens.length!=3)
                        System.out.println("Incorrect file format");
                        return false;
                   int tnX = 0,tnY=0,tN=0;
                   try
                        System.out.println("Trying first token: "+tokens[0]+".");
                        tnX = Integer.parseInt(tokens[0].trim());
                        System.out.println("Trying second token: "+tokens[1]+".");
                        tnY = Integer.parseInt(tokens[1]);
                        System.out.println("Trying third token: "+tokens[2]+".");
                        tN = Integer.parseInt(tokens[2]);
                   catch(NumberFormatException e)
                        System.out.println("Could not parse data: ("+tnX+","+tnY+","+tN+")");
                        return false;
                   nX = tnX;
                   nY = tnY;
                   grid = new char[nX][nY];
                   initGrid();
                   // parse input data and verify correct file
                   while ((current = br.readLine()) != null)
                        tokens = current.split(delimiter);
                        grid[Integer.parseInt(tokens[0])][Integer.parseInt(tokens[1])]=tokens[2].toCharArray()[0];
                   } // end while
                   System.out.println("File loaded successfuly");
                   return true;
         catch (IOException e)
         e.printStackTrace();
         return false;

    Hi everyone, I've got it figured now.
    There indeed was some invisible characters hidden in the string.
    When I added the code:
         char[] cs = tokens[0].toCharArray();
         for(int i = 0;i<cs.length;i++)
              System.out.println("Character "+i+": "+Character.getNumericValue(cs));
    I get as an output:
    *Character 0: -1*
    *Character 1: 1*
    *Character 2: -1*
    *Character 3: 0*
    *Character 4: -1*
    *Character 5: 0*
    *Character 6: -1*
    *Character 7: 0*
    *Character 8: -1*
    This comes from the way that the files are being generated: via a DataOutputStream.
    The following code inserts the hidden characters, and I can get around this by using a BufferedWriter
    OFFENDING CODE     File file = new File(fName);
         MapPoint[] points = getMapPoints();
         fos = new FileOutputStream(file);
         dos = new DataOutputStream(fos);
         dos.writeChars(new String(""+wX+","+wY+","+points.length+"\n"));
         for(int i = 0;i<points.length;i++)
              dos.writeChars(""+points[i].x+","+points[i].y+","+points[i].type+"\n");
    Thanks to everybody for all your help!
    - Andrew                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Installation of XI 3.0 on the J2EE Engine Support Packages 09

    during the install of the XI i receive the following error: ERROR CJS-00081 Assertion failed: in undefinedThe returncode of the central profile import is not 0 but 1. check /tmp.../dbconnect.html for more information. has anyone had this error??? tha

  • Material weight change in Sales Order

    Hi , In a Sales Order, the weight of a material gets copied from the material master.Is it possible to change the weight of a material in a sales order /Quotation if it is maintained as 0  in Material master. Our client used to change the weight in s

  • Exporting keywords with file

    somewhere, much earlier, in this forum i asked how i could export my files with only assigned keywords. I DO NOT want the "parent" keyword. For example if GRANDMOTHER (parent) contains mary (child) I want only the mary exported. I read that the answe

  • Problems compiling and running a servlet

    I have been trying to compile and run my servlet program to no avail. Please help. I am using Tomcat 5.5 and j2sdk1.4.2 These are the errors I keep getting. I have already set the classpath appropriately. MyServletTest.java:5: package javax.servlet d

  • Not create COPA document after Billing

    Hi Experts:    my company product strategy  is  MTO (make to order).It's not created COPA document after billing .I don't know when the COPA should be created. After Billing or after running VA88 .so  I tried to run VA88. I got a COPA document after