How to to scan a string, char by char?

Hi i have some xml data, i want to scan the string char until it sees > for the first time. Then it adds the following data until it sees <, at which point it stops. So i should get s2tidm1 from "<server>s2tidm1</server>"
The problem with the below code is that sa.next() gives me the whole string as there is no space, is there a sa.nextChar() or something similar?
Code following -- Thanks Peter
import java.io.*;
import java.util.Scanner;
import java.util.*;
public class xmltestmod {
static String data =  "<server>s2tidm1</server>";
    public static void main(String args[]) {
          Scanner sa = new Scanner(data);
          String pete = " ";
          String temp =" ";
          while (sa.hasNext())          {
               temp = sa.next();
               System.out.println(temp);
               if (temp.contains(">")){
                    while (true){
                    System.out.println("Entering if");
                    temp = sa.next();
                    pete = pete + temp;
                         if(temp.contains("<")) break;
     System.out.println(pete);               
     sa.close();
}

>
I got muiltiple xml lines in a array, i want to loop
the array and strip out the tags so only the data is
left. Thats why i didn't use the xml apis out there
as you need to say starttag = "<Server>";, endtag =
"/Server>", but i just want to say store all data
inbetween < and >, that way i can loop through the
whole array.
Actually if you use the SAX parser, rather than the DOM parser, it will call a method of your chosing for each text element, and you can just ignore the callbacks for tags etc. if you wish.
Can you explain abit more about hte substring and
index of part please.Check the Javadocs. Substring chops part of a string out, indexOf finds the first occurance of a character.

Similar Messages

  • How do I avoid Error 85 in Scan From String scanning VISA read buffer?

    I have encountered an Error 85 with my Scan From String VI. I have a timed
    loop to read data from a device (flowmeter) using a serial port. This device takes
    periodic measurements and sends the reading which contains a numerical value to the serial port COM1. It cannot be read continuously, and the period
    between measurements may vary, so I decided a timed loop would be better than a while loop.
    The VI begins with VISA Configure Serial Port and then
    goes to a VISA Write which sends the message to the device to begin
    taking measurements. After this, the device usually says "TAKE FLOWMETER READINGS" to the terminal, thereafter only sending numbers. Then begins my timed loop containing VISA Read. I
    am taking the read buffer two places.
    First, I am taking it to an Array to Spreadsheet String with the
    Format String %.3f, as was in the Write to Text File example. Then I am
    using Concatenate Strings with this string and also a string containing
    the System Time. This string goes to Write to Text File, which I have
    configured using Open/Create/Replace File outside of the loop.
    Second, I am taking the read buffer to a waveform chart. I thought
    it would be a good idea to use Scan From String to convert the string
    into a DBL which I am then sending to the waveform
    chart.
    I am not sure if the initial "TAKE READINGS" message is giving me an error. I was able to get one reading saved to my text file from the device.
    Also the format string for my Scan From String is %.3f
    I am getting the Error 85 at the Scan From String only sometimes.
    When this happens, there is no data being written to the text file. But
    other times, I get data and it writes to the text file just fine (but
    rounds to nearest whole number).
    Any help would be greatly appreciated! This serial port device has been giving me a lot of trouble.

    Is this what you mean? Did I wire the shift registers correctly?
    I didn't know if you meant to Concatenate before Scan From String or Concantenate before or after VISA Read?
    Message Edited by YeungJohn on 11-20-2008 03:48 PM
    Message Edited by YeungJohn on 11-20-2008 03:49 PM
    Attachments:
    SerialShiftVI.JPG ‏87 KB

  • Scan from string error 85

    Hi Everybody,
    I'm trying to use LabView to
    process some data.  The data, although it was collected via labview,
    has been written out to csv file format.  I have been able to
    successfully open the file and use the search split string function to
    remove the "header" from the data stream.  Now I'm trying to parse the
    header to extract some pieces of the info that is there.  I'm trying to
    do this with the Scan from String VI.  
    So
    far I've been able to retrieve the Specimen ID from the first line of
    the header by setting the format string input of Scan from String as
    "Specimen ID ,%s", which works just fine.  Problem is, when I
    adjust
    the format string to include the next piece of data I want, I
    inevitably get an Error 85, which is a failed scan.  In fact, I
    get an err85 every time I try to extract something from after the
    second line.  I've attached a VI in which I cut and pasted an
    example header string in as a string constant and an example of how I'm
    trying to extract the values.  I've tried playing around with
    spaces and different formats, but get the err85 no matter what I do
    (unless I extract the first line).  I have a hunch that it has
    something to do with the EOL marker, but no idea how to work around it.
    A search of posts here show that a lot of people have issues with the
    scan from string vi, but nobody I could find had this exact
    problem.  I've also considered using the spreadsheet spring to
    array function, but because I have a mix of commas and EOLs it doesn't
    seem to work either. HELP! I really don't want to have to write this
    over in VBA/Excel.
    Thanks,
    Turk
    Message Edited by YoungTurk on 07-29-2005 10:36 AM
    Attachments:
    Scan.vi ‏12 KB

    You should probably parse it line by line (See attached, LabVIEW 7.1)..
    The attached example shows one possibility to get all the Items and values out. Not all values are strictly numeric so you would need to adapt the code a little bit. (This is just a very rough 1 minute draft).
    You might want to cosider to extract all values into a cluster for further processing, Have a look at the example  posted in this thread . It can be easily adapted to read the values in the proper format (DBL, I32, Date, String, etc.) depending on the item name.
    Good luck!
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ScanMOD.vi ‏30 KB

  • Wrong use of "Scan From String" function in a while loop?

    Hi,
    I've got a "Scan From String" function inside a while loop. On the first iteration it converts correctly the number passed by the input string (for example 4) But on the second one it has only spaces (one or more \s) as input string.
    I expected to obtain a zero as output (as it does always that it can not make any conversions, as I am supposed to) but indeed, i subtracts 1 from the previous number (according to the number indicated as example I would obtain a 3 as output)
    What's wrong with this?
    Does the function fails on this case?
    The rest of the diagram o the VI is expected to manage a 0 on that situation, like others in which the conversion is not made.
    Andres.

    I have simplified the VI evading calls to other VIs and trying to reproduce the mistake.
    The type of string I introduce to reproduce the mistake is:
    clock 3 (30) clock (40)
    Forgetting to introduce a number between the second "clock" and the following parenthesis, I would manage it programmatically with code that isn't included.
    Then "Scan From String" is supposed to do not make a conversion. But it leaves a 2 as output (in this example)
    I have realised, unbelievable but true, that it has matter with the number I substract to the output number (if it were 2, I would obtain 1 as output and so on)
    Excluding that, I got the conversion made before as output, 3, on the second time that "Scan From String" executes. But, how can this func
    tion as bad?
    I am using LV4 on an old PC. I have tried to reproduce it with LV6 and it works. But it isn't desirable for me, I would have to convert a lot of VIs and surely I will find a lot of errors due to the conversion (I have already tried)
    Attachments:
    EXTCLOCK.VI ‏26 KB

  • Using scan from string to convert a string into a number

    I wanted to use scan from string to change a string into a decimal number, but when the string is, for example, 9.14123E-2 it just returns 10. How can I get it to return .00914 or 9.14E-2(as a number not a string). Would there be something easier than scan from string? I'm using labview 5.1. Thank you!

    Hello,
    May be you can checkout the attached example.
    Perkash Mohan Lal
    Institute of Semiconductor Technology
    Technical University Braunschweig
    Attachments:
    string_conversion_1.vi ‏44 KB

  • Error 1 occurred at Scan From String (arg 1)

    I am communicating with the AT Trainer 5000 via serial port to USB converter.
    I installed all drivers of converter successfully and it is shown in MAX as com port. I also installed VISA software. 
    I am using labview 2013 version.
    When I connect the hardware to PC via usb to serial converter, try to run the program for seeing of real time graphs, I am receiving this error Error 1 occurred at Scan From String (arg 1) whereas there is no waveform shown in waveform chart. 
    Also read buffer didn't show an incoming data at read buffer.
    Other details for this error is
    Possible reason(s):
    LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
    Also pics of error is:
    Program is also attached. Please checked the also.
    Expert please help me how to get rid of this error.
    Attachments:
    Project.vi ‏23 KB

    Since you are using the termination character, you should not use the Bytes At Port property node.  Just set the number of bytes to read for the VISA Read to something really high (larger than what you expect in a single transmission).  The VISA Read will stop reading once the termination character is reached.
    Now, what is the format of the data coming from the instrument?  I see you are converting an ASCII Hex string into a number while trying to also turn it into a double.  That is likely why you are getting your error.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions

  • How to get substring from string using index?

    hi,
    here i am having string ,
    i want the pullareddy from below line ,
    i know how to get from substring.
    but i want to get the above using "index",
    can any help how to do it?
    String str1="janapana,pullareddy, in malaysia";
    jpullareddy

    get the start index with indexAt("pullareddy")
    get the end index with adding the length of the word to the start
    get the char[] of str1 with toCharArray()
    make a new string with the chars from start to end index.

  • Scan from string to Bundle by name

    I would like to take the output of "Scan From String and feed it into a Bundle by Name. There is no pre-existing bundle so I wonder if I can use a Cluster constant for the Input cluster. If so how is the cluster constant defined.
    My goal is to read strings from ini file sections, split out names and limits and put them into a cluster or array of clusters that can be stored as TestStand Locals or FileGlobals.
    Thanx,
    jvh 
    Solved!
    Go to Solution.

    jvh75021 wrote:
    There is no pre-existing bundle so I wonder if I can use a Cluster constant for the Input cluster. If so how is the cluster constant defined.
    This is a very common thing to do upon initialization - bundle things up into a cluster and carry it around to use throughout the program, in sub-vi's, etc. I'm glad you're not just throwing them all into locals or globals!
    Yep, you'll just use a Cluster constant into the Bundle the first time it's bundled. To make that initial cluster constant, take your known output cluster just create > constant. So to answer your question, the cluster constant is defined by the known output.
    However, if this cluster ever changes during development, and it will , you'll be changing every single cluster inside sub-vi's and that initial constant... or.. you'll follow Ben's advise and make a TypeDef!
    Message Edited by Broken Arrow on 04-09-2010 03:22 PM
    Richard

  • Scan from string

    Trying to use the Scan from String VI to break apart a string. How does one get it to accept strings with blanks embedded?
    Solved!
    Go to Solution.
    Attachments:
    Untitled 2.vi ‏7 KB

  • Scan for string

    HI erveryone,
    I am working with the Scan from String fuction, but I have a problem. The string that I have as input is "temp=32.2", so I am using the Scan function as follows:
    But as output 1 I have "temp=32.2" and 0 in the output 2.
    Does anyone have an idea of how to separate "temp" in output1 and 32.2 in output2?
    Thanks for your help
    Raymundo Cassani
    Solved!
    Go to Solution.

    The you need to program around it, for example as follows. There are many ways to do this...
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ParseString.png ‏4 KB

  • Why am I getting error 85 from 'scan from string' VI?

    Data is in CSV format from an Excel spreadsheet. It may be an empty string but I compare the data to an empty string and, if is empty, then I input  the string constant '0' to the 'Scan from String' VI. I'm using 3 probes to try to debug this.
    The 1st probe is at the output of an 'Index Array' VI which extracts the element of interest from the array loaded from the spreadsheet file. The probe declares it's type as 'string' and the probe content is blank. I assumed that this means 'empty string'.
    The second probe is at the output of an 'Equal' VI which compares the data described above with the empty string constant "". The result is False. Why is this? How do I tell what the CSV data is? If the probe is blank can it be a Null character or NaN or is it interpretted as a blank string? The Excel file has all fields defined as 'text.
    The third probe is also blank.
    When the data is interpretted by the 'Scan from String' VI it fails. I also have the default pin wired to a double constant  with a value of o. Shouldn't this be used by the VI in the event the VI can't interpret the string passed to it? 
    Thanks for any help,
    Frank   

    fr@nk wrote:
    The second probe is at the output of an 'Equal' VI which compares the data described above with the empty string constant "". The result is False. Why is this? How do I tell what the CSV data is? If the probe is blank can it be a Null character or NaN or is it interpretted as a blank string? The Excel file has all fields defined as 'text.
    Yes, it can be a Null character. NaN is something else. To really see what's there you can place an indicator and then change the display mode of the string indicator to Hex Display Mode.
    You have not indicated what your format string is. Why don't you upload your code along with your data. Just out of curiosity, what are you using to read the file? Are you using Read From Spreadsheet File?

  • Quick String / char  question

    Hi, i have to write a encrytion method for a assignment, it must take a string, move the characters on by a set number given by the user and return the result.
    public class Encryption
        int key;
        public Encryption(int k)
            key = k;
    public String encrypt(String si)
    si = si.toUpperCase();
    int i = 0;
    for (int index = 0; index< si.length(); index++);
    char c = si.charAt(i);
    int n = c - 'A' + key;
    char a = (char)(n + 'A');
    return si ;
    }it compiles, but what i need to know is how to i get my new chars (that have been moved the set amout) back into a string that is returned to the user, as i cant seem to find the code i need to do this???

    String result = "";
    Each time through the loop, you will want to add it to the result
    result = result + a;This is poor adviceimport java.io.*;
    public class Encryption{
       public static void main(String[] args) {
          new Encryption();
       Encryption(){
          String toEncyrpt = "The quick brown fox jumps over the lazy dog";
          int key = 0;
          try{
             BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
             System.out.print("Enter a number for the encryption key ");
             key = Integer.parseInt(br.readLine());
          }catch(IOException e){}
          String encrypted = encrypt(toEncyrpt, key);
          System.out.println("Encrypted string : "+ encrypted);
          String decrypted = decrypt(encrypted, key);
          System.out.println("Decrypted string : "+ decrypted);
        public String encrypt(String s, int k){
           StringBuffer sb = new StringBuffer();
           for(int i=0; i<s.length(); i++) {
               int temp = (int) s.charAt(i)+k;
               sb.append((char)temp);
           return sb.toString();
        public String decrypt(String s, int k){
           StringBuffer sb = new StringBuffer();
           for(int i=0; i<s.length(); i++) {
               int temp = (int) s.charAt(i)-k;
               sb.append((char)temp);
           return sb.toString();
    }

  • Regular expression for Scan from String

    I am trying to pick out three numbers with pattern $number1:number2:number3# from a stream, for instance 8.559509#$-1.686432:-2.427051:-7.281153#$-6.160924​:-1.763356:
    So far, I use "Scan from String" with Format string "$%f:%f:%f #". However I don't know how to ignore/delete the items before $. Would you like to help me with that? Cheers

    You know that your sequence of numbers begins with the $ and ends with the #, so you can separate them into groups first, then separate each number out.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • HOW DO I WRITE A STRING TO FLAG WHEN A CELL HAS OR 17 CHARACTERS?

    HOW DO I WRITE A STRING TO FLAG WHEN A CELL HAS < OR > 17 CHARACTERS?

    Hi Tassytiger,
    A "string" is just a string of characters. Examples are qwerty, 123abc, 43πbono. there are several ways to write one. A more precise description of your end goal might help answer "How do I write a string."
    To the current version of your specific question:
    What I actually need to achieve is a situation where, when I enter <17 Char. or >17 Char.
    inadvertently then tab to the next cell, I get the following response in the active cell:
    The cell immediately below "17 character ID" displays an error triangle. These are shown when the formula in a cell produces an error message. they are system generated and require two things to happen: The cell must contain a formula AND something must have happened to cause that formula to produce an error.
    I don't wish to add any columns to my s/s but would like to apply the rule to the current column just as i would change the text or fill colour.
    The difficulty there is that a cell may contain entered data, OR it may contain a formula. You want to enter data (a string of characters) and you want to produce an error triangle if that string has more or fewer than 17 characters. Evaluating the length of the string requires a formula. Getting the string into the cell requires direct entry (in your scenario). The two are not compatible within the content of a single cell.
    Terry's example uses a formula in column B to measure the length of the string in column A. If the length is 17 characters, the IF statement produces the empty string ( "" ), and the cell in column B appears empty. If the string is not 17 characters long, the IF statement produces the string "Not 17 Chars!"
    His formula is easily changed to produce an error triangle in place of "Not 17 Chars!":
    B1: =IF(LEN(A1)=17, "",17/0)
    In this version, if the length of the string in A1 is not 17 (characters), the formula will attempt to divide 17 by 0, and will produce a 'division by zero' error.
    But, as with all of the other suggestions, this one will require a new column to provide space for the formula and it's result.
    Changing the text or fill colour can be done using conditional formatting. Changing content of the cell (eg. choosing between the entered string of characters and the error triangle) cannot.
    Conditional formatting rules compare the content of a the cell to be formatted with either a fixed value (written into the rule) or to the content of another cell. In my examples (and in Ian's examples) above the rules compared the content of the cell to be formattes to the number '17'. The number was generated by a formula which measured the length (in characters) of the text in the cell where the ID was entered, and reported that length as a number.
    A way to show a red triangle using conditional formatting is to use Image fill as the default fill of the cell, then use a colour fill as the conditional fill to hide the trialngle when the conditions are met. Here's the same example as used above, with this technique applied to column B:
    The same formula is used in column B as in my previous example. Type size is set to 1 point (note the black dot, visible in the green filled cell) to keep the numbers from obscuring the triangles. The triangles are shapes, inserted onto the canvas (not into the table) from the Shapes button in the tools. Their fill colour has been changed to red, a 12 point exclamation sign character ha been typed into the shape and its text colour set to white, and the triangle's size has been reduced as much as possible without triggering the overflow symbol (boxed plus sigh) to appear.
    The triangle image (and some of its white background) was made into a png image file by taking a screen shot, and the image was inserted into all of the cells in the body rows of column B as an image fill, using the Graphic inspector. The conditional format rule below was then applied to the body row cells in column B.
    Finally, you can apply conditional formatting to the cell containing the ID. This will still require another column to contain the values to which the content of the ID cell will be compared, but that column may be hidden, or may be located on a separate table.
    The method requires an second cell for each cell contining an ID, and uses a formula that makes the contents of the second cell the same as that of the ID cell IF the ID cell contents are 17 characters long.
    Here's a sample. Table 1 is column A of the same table as above. Table 2 is a single column table holding the comparison cells.
    As in the example above, the cells on table 1 were given an image fill. The conditional format rule replaces that with a white colour fill when the cell contains the same text as its partner cell in Table 2.
    This is the rule for cell A2. In A3, the cell reference is to Table 2::A3, and in A4, to Table 2::A4. The cell references in conditional format rules must be edited individually.
    Regards,
    Barry

  • SCAN FROM STRING IN LABVIEW 8.5

    Hi guys, i need help in this VI that i attached. I'm doing a project using serial connection between PIC18f4520 and Labview 8.5. I am monitoring the voltage and current. In the Read String box, (eg. when i run the VI, it will display 4.19v 4194uA.) How can i link this result to display on the graph simultaneously as the value of the voltage and current will vary when i adjust the value of the potentiometer.Can i use scan from string to linkup or ? i need help . thx alot people. 
    Attachments:
    fal Serial Write and Read with graph.vi ‏48 KB

    Hi, from the picture i have attached below, how can i link my output onto Voltage, Current and Temperature ? It seems that it can only display on the read buffer box. After which i need to gather the output Temperature to display onto the gragh as i need to monitor the temperature. Another problem i face is that how can i fix the byte read at 21bytes because if it is more than or less than 21 bytes, it will display funny characters(see 2nd attached pic below).
    Attachments:
    fal Serial Write and Read with graph 2.vi ‏48 KB

Maybe you are looking for

  • Solving installation problem on new server

    I just wanted to share my experiences installing Solaris 11 on an x86 server that I built. When I first constructed the box with an ASUS motherboard and an Intel Xeon processor, I was able to install CentOS Linux but not Solaris as the kernel refused

  • Cannot display Courier New and Index Marker font in FrameMaker 9/10 w/ Windows7

    Hi. Our company recently rolled out Windows 7 x64 and this seems to have had a negative impact on display fonts in FrameMaker 9 and 10. What happens is this: When we open a FrameMaker file, any text in Courier New (which we use for command/code synta

  • Unhappy with OS6

    I'm am fed up with OS6. I'm ready to trade in this phone after only 2 months for a non blackberry phone. I am already telling everyone it got terrible It is so slo its not funny. I am missing calls that I can answer because the phone is so slow they

  • Reminders bug/feature with "a" and "p"

    Hey gang I've already submitted to Apple Feedback, but thought it was worth documenting this on the forum for future possible workarounds/reference. The Reminders app has automatic date/time recognition. If you type "Meet Joe at 4pm", the note gets c

  • Thousands of playlists

    my itunes makes thousands of blank playlists entitled "My Playlist 20090109" that get re-created as soon as i delete it. i think they're the cause of my itunes being slow, any help? thanks.