Compare two string in different line in textarea

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextCounterPanel extends JPanel {
private JTextArea textInput;
private JLabel lineCountLabel;
                    public TextCounterPanel() {
                    setBackground(Color.DARK_GRAY);
                    textInput = new JTextArea();
                    textInput.setBackground(Color.WHITE);
                    JPanel south = new JPanel();
                    south.setBackground(Color.DARK_GRAY);
                    south.setLayout( new GridLayout(4,1,2,2) );
                         JButton countButton = new JButton("Process the Text");
                         countButton.addActionListener( new ActionListener() {
                              public void actionPerformed(ActionEvent evt) {
                                   processInput();
                         south.add(countButton);
                    lineCountLabel = new JLabel(" Number of lines:");
                    lineCountLabel.setBackground(Color.WHITE);
                    lineCountLabel.setForeground(Color.BLUE);
                    lineCountLabel.setOpaque(true);
                    south.add(lineCountLabel);
                    setLayout( new BorderLayout(2,2) );
                    setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                    JScrollPane scroller = new JScrollPane( textInput );
                    add(scroller, BorderLayout.CENTER);
                    add(south, BorderLayout.SOUTH);
public void processInput() {
String text,vin; // The user's input from the text area.
text = textInput.getText();
vin =text.substring(25,42);
lineCountLabel.setText(" vin: " + vin);
} // end class TextCounterPanel
How can I compare two string in different line in text area

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextCounterPanel extends JPanel {
private JTextArea textInput;
private JLabel lineCountLabel;
public TextCounterPanel() {
setBackground(Color.DARK_GRAY);
textInput = new JTextArea();
textInput.setBackground(Color.WHITE);
JPanel south = new JPanel();
south.setBackground(Color.DARK_GRAY);
south.setLayout( new GridLayout(4,1,2,2) );
JButton countButton = new JButton("Process the Text");
countButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
processInput();
south.add(countButton);
lineCountLabel = new JLabel(" Number of lines:");
lineCountLabel.setBackground(Color.WHITE);
lineCountLabel.setForeground(Color.BLUE);
lineCountLabel.setOpaque(true);
south.add(lineCountLabel);
setLayout( new BorderLayout(2,2) );
setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
JScrollPane scroller = new JScrollPane( textInput );
add(scroller, BorderLayout.CENTER);
add(south, BorderLayout.SOUTH);
public void processInput() {
String text,vin; // The user's input from the text area.
text = textInput.getText();
vin =text.substring(25,42);
lineCountLabel.setText(" vin: " + vin);
} // end class TextCounterPanel

Similar Messages

  • Comparing two words in different lines

    hi frens, please help me.
    let say each line has 2 words
    <word1> <word2>
    what i am going to do is to compare the first word for each line. for example, let say this is the input file:
    hello world
    baby good
    hello baby
    good stuff
    hello good
    good job
    what i want for the output is:
    hello = world; baby; good
    baby = good
    good = stuff; job
    so it compares the prefix, if equals, then just print the second words behind. they are stored in hash table. thanks.

    Cross-posted,
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411889&tstart=0&trange=15

  • How to compare two strings whether both are equal while ignoring the difference in special characters (example: & vs & and many others)?

    I attempted to compare two strings whether they are equal or not. They should return true if both are equal.
    One string is based on Taxonomy's Term (i.e. Term.Name) whereas other string is based on String object.
    The problem is that both strings which seem equal return false instead of true. Both string values have different special characters though their special characters are & and &
    Snapshot of different design & same symbols:
    Is it due to different culture or language?
    How to compare two strings whether both are equal while ignoring the difference in special characters (& vs &)?

    Hi Jerioon,
    If you have a list of possible ambiguous characters the job is going to be easy and if (& vs &) are the only charracters in concern awesome.
    You can use the below solution.
    Before comparing pass the variables through a replace function to standarize the char set.
    $Var = Replace($Var,"&","&")
    This is going to make sure you don't end up with ambiguous characters failing the comparison and all the char are "&" in this case.
    Similar technique is used to ignore Character Cases 'a' vs. 'A'
    Regards,
    Satyajit
    Please “Vote As Helpful”
    if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

  • URGENT! I need to compare a String with a line in a .txt file

    I'm a college student and I have a very simple question i guess. I need to write an if procedure which compares if a line of a .txt file is equal to something, but I just don't know how to do it. HELP!

    What specifically are you asking for? How to compare two strings?
    String s = "cat";
    String t = "Cat";
    if (s.equals(t))
       System.out.println('They are equal');    // does not print out
    if (s.equalsIgnoreCase(t))
       System.out.println('They are equal');    // prints out

  • How to Compare two strings in PL/SQL

    Hi All,
    I need to compare two strings whether they are equal or not in PL/SQL.Is there any function to comparing the strings.

    Yes, the = sign.
    Are you after something like:
    IF v_string1 = v_string2 THEN
    ELSE
    END IF;?
    Edited by: Boneist on 27-Aug-2009 11:41

  • Compare two strings in a formula

    Hi,
    I'd like to know if there's a way to compare two strings in a formula ?
    I have this consition:
    IF(@SUBSTRING(@NAME(@CURRMBR(TIME_FROM)),5)==@NAME(@CURRMBR(TIME)))
    But the == operator can only compare two data.
    Thanks,
    Cyril

    Hi,
    thank you both for your answers.
    When I figured that the == operator was for data only, I didn't even try to compare member names.
    I finally used the solution that Cameron suggested in another conversation. I created a date measure, and loaded some data since the beginning of my time to the end.
    It starts in 1974 (annually), then becomes monthly data, and then daily data from 2009, so it's not so many blocks to br created. In the end I have the same value for "from 2008"/"from Apr 30", and I can easily compare my dates.
    Note that I could have also used the @TODATE function, which turns a date into a number, but the format of date is limited and doesn't fit the format of my member names, so I got lasy... and I'm not sure my users would have apreciated that ;)
    Thanks, this post is solved.
    Cyril

  • How to compare two database on different servers

    hi,
    I want to compare two database on different servers in oracle.first i want to ckechk thier structures and then data.i m using oracle 10.2.0.plz help me out
    Thanks in advance

    In terms of structures, there are various tools out there that can do this, such as TOAD which can do a database compare.
    In terms of data comparisons, that will depend on what sort of results you are expecting to see. I'm sure some tools will do it for you, but it can be just as easy to write your own comparison using a database link from one database to the other.

  • Compare two strings for partial or full match

    I have been trying to figure out away of comparing two strings.
    I can get the full string matching to successfully work but am struggling on how to get partial eg wildcard search working.
    say I had names like paul Duncan, George Morrison.
    I have split them up so its now paul , duncan i then use the users entered string to compare it against the name name to see if it matches anything in the first name or the last name if it does i added it to an arraylist.
    however i have tried t use a indexof as i believe this looks for similarity (Substring matches?) but it always returns -1.
    Could anyone possibly direct me to a method that will allow me to use partial text string to match it against stored user names.
    eg user enters pa
    I would return anything that would contain pa
    thanks for any help

    thank you for the reply
    Sorry I forgot to put in the code.
    This is a reduced down version including the read in from a text file as well as the index of if statement and the adding of it to an array list.
    public class FindContact {
    String res;
    /** Creates a new instance of FindContact */
    public FindContact() {
    public Object[] FindAUser(String passSearch) {
    System.out.println("getting here");
    ArrayList found = new ArrayList();
    String patternStr = ",";
    int j, i = 0;
    try {
    BufferedReader in = new BufferedReader(new FileReader("H:\\out.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String[] fields = str.split(patternStr);
    //for(j=0;j < fields.length;j++) {
    if (fields.length != 0) {
    if (passSearch.indexOf(fields[0])!=-1 || passSearch.indexOf(fields[1])!=-1) {
    found.add(str);
    System.out.println("ENDDDDDDDD value ");
    in.close();
    } catch (IOException e) {
    System.out.println(e.toString());
    Object[] foundResult = new Object[found.size()];
    foundResult = found.toArray();
    if (foundResult.length >= 0) {
    System.out.println(foundResult.length);
    return foundResult;
    Hope that helps as it has confused me and am not sure why it is not returning a value.
    Should I maybe use the contain method instead to search for the user inputted string?

  • Compare two strings and the save the greater

    To devolop a vi,it can compare two strings.A string is gived,the other is saved previously.If greater,then save,or do nothing.

    Hi,
    I am assuming by "greater" you mean the string length.
    Use the string length function from the strings palette, with shift-registers on a while loop. Write to the shift-register the "greater" string.
    I am attaching a diagram screenshot for this. NOTE: depending on how you want this VI to run, you can move the input and output string control and indicator inside our outside the while loop.
    Hope this is what you were looking for.
    Khalid
    Attachments:
    strlen.gif ‏17 KB

  • Comparing two numbers with different formats

    Dear Java developers
    I am trying to compare two numbers but they have different formats. long x = 8981261369, Object obj = "8,981,261,369".
    I am trying to see if this two values are equal which is the case in the example above except one has a thousand separator but not sure how to do that.
    How can I lose the thousand separator and just compare them as two long values.
    Your input will be much appreciated
    Thanks

    iu433 wrote:
    I need a generic way of doing this. Because sometimes the Object does not have a thousand separator. Can i use some kind of NumberFormat to do this.You'll need to know what formats the string (not the number--as already mentioned, numbers don't have formats) can have, and then try them one by one.
    Of course, there can be some ambiguity. Does "123,456" represent one hundred twenty three thousand four hundred fifty six, or is that comma a decimal separator, and it represents one hundred twenty three and four hundred fifty six thousandths?
    The point is, you have to have a clear definition of what formats are allowed and how to determine which one it is. There's no magic way for Java to do that for you.

  • Compare two dates in different format.

    Hi
    I want to compare two dates....one of which is in the timeStamp format ("yyyy-MM-dd HH:mm:ss")
    and the other is in java.util.Date i.e Tue Oct 11 10:22:47 GMT+05:30 2005
    Do I have to tokenise and then compare them.Is there any better approach?
    I want to find out which is greater/smaller one.
    Pls help.
    Regards,
    Sandip.

    I would convert both to Date and compare them. To convert String to Date check java.text.SimpleDateFormat and its parse(...) method.
    HTH
    Mike

  • Comparing two strings

    How do you check to see if two strings have dashes in the same places?
    For example:
    String one= "dfsdt-ra-s-dsfd";
    String two= "dsfst-da-s-dsfd";
    would return true.
    String one="jhsdjfk-dsf-sdf"
    String two="d-dsf-dfsf-f"
    would return false.
    This is what i have:
    if (one.indexOf("-") == two.indexOf("-")) {
    return true;
    The problem with this if statement is it only checks the first time the dash come and not the whole string.
    How can I check the whole string to compare the index of string one and string two every time the dash come up.

    Hey,
    Check this code out, compile it and you should get it. Let me know if you have any questions.
    Thanks
    Riz
    public class StringCheck {
         String s1;
         String s2;
         boolean AreEqual;
         int lens1,lens2;
         public StringCheck(){
              s1="dfsdt-ra-s";
              s2="dfsdt-ra-s";
              AreEqual=false;
              lens1=s1.length();
              lens2=s2.length();
         public boolean CheckTheString(){
              boolean localcheck=false;
              if(lens1==lens2){
                   for(int i=0;i<lens1;i++){
                        if(s1.charAt(i)==s2.charAt(i)){
                             localcheck=true;
                             i++;
                        if(s1.charAt(i)!=s2.charAt(i)){
                             return false;
              if(localcheck)return true;
              else return false;
              //return true;
         public static void main(String args[]){
              StringCheck c = new StringCheck();
              boolean validate=c.CheckTheString();
              if(validate)
                   System.out.println("The string are equal");
              else
                   System.out.println("The String are not equal");
    }

  • Compare two String

    String s1 = "ABC";
    String s2 = "ABC";
    *if (s1 == s2){*     //This tests true
    *if (s1.equals(s2)){*     //This tests true
    *if (s1.equalsIgnoreCase(s2)){*//This tests true
    My understanding is s1 refers one String object with the value ("ABC"); while s2 refers another String object with the value ("ABC"); So s1 and s2 actually refers to different objects.
    Is this correct?
    If so why the above test true?
    Thanks
    Scott

    Just to dig a little further...
    For
    String s1 = "ABC";
    and
    String s1 = new String("ABC");
    You mentioned:
    if((Object)s1 == (Object)s2){
    return true;
    should return false because the two String Object references s1 and s2 are stored at different memory locations*
    --My question, the fact that the comparision of ((Object)s1 == (Object)s2){... returning  false is:
    1) because they refer to different objects which are stored ar different locations?
    OR
    2) due to the above said: two String Object references s1 and s2 are stored at different memory locations
    --I prefer the 1).  But not so sure.
    --If answer is 2),  it will contradicts in following for s1 and s2 are stored at the different locations but the comparision ((Object)s1 == (Object)s2  will return true, i.e.,
    String s1 = "ABC";
    String s2 = "ABC";
    uses String.intern at compile time
    so
    s1 reference at aaa looks for the String object at xxx
    s2 reference at bbb looks for the String object at xxx
    this way
    if((Object)s1 == (Object)s2){
    return true;
    } should return true....
    Further,
    String s1 = "abc";
    String s3 = s1;
    Now, both s1 and s3 refer to the same Object ("abc"), but s1 and s3 are stored at different locations. Yet,
    if (s1 == s3)... will return true.
    This further indicates that the comparision of two references only has something to do with the actual location of the object, not the location of the reference itself.
    Like to get your opinion on this issue.
    Thanks
    Scott

  • Compare two strings in an array

    Hello!
    Please feel free to give me hints, but do not give me any code.
    Ok, here is what I am trying to do, I whant to compare my input string whith strings allready stored in the array. If my input string equals any of the allready excisting strings, a error wil show upp, otherwise store the new string in next avalibal position. I do not seem to get the method right for comparing the strings. here is the method I have written so far, please take a look and give me a hint, but no code. :)
    //Check if a user already excists     
    public void compareNames (People in_array [], String in_name) {
              for (int i=0; i<value.peopleCount; i++) {
                   if (in_name.equals(in_array.getPeople())) {
                   System.out.print("The user already excist, please chose another name");
    }value.peopleCount is an global count value for people arays.
    getPeople get the name from the people class.
    Martin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    A couple notes here.
    The name compareNames() is misleading if it is going to do what you described. A comparison will generally not have side-effects like outputting error messages to the console or adding new items to an array. It would be better if you called the method addIfNew(), and returned a boolean indicating whether the name was new or not. The caller would then be responsible for displaying an error message if the method returned false.
    I also suggest you use a List such as ArrayList instead of an array, otherwise you will have to resize and copy your array every time you add something to it that exceeds the array size, and will allow you to do away with the global peopleCount.

  • Compare two dateTime with different timezone

    HI, All,
    I found a strange thing when compare two dateTime in BPEL;
    In my BPEL process, client passed a date time to the process , and the process compare the date time with current data time.
    1.client pass cutoffDate to process
    2. in a switch activity, I compare cutoffDate with current date. code:
    bpws:getVariableData('cutoffDate')<=xpath20:add-dayTimeDuration-to-dateTime()
    but seems this compare ignored the timezone information.
    For example:
    cutoffDate=2010-03-05T06:17:38.838+00:00
    currentDate=2010-03-05T14:10:38.838+08:00 this time =2010-03-05T06:10:38.838+00:00
    but cutoffDate<currentDate == true... seems it ignored the timezone info..
    This is a bug or I used a wrong compare function?
    Thanks.
    Edited by: Colin Song on Mar 5, 2010 3:28 PM

    Hi Colin,
    Please go through below link, there is topic about calculating difference between dates. Hope you find solution.
    http://blogs.oracle.com/reynolds/2007/07/19/
    Please let me know, if still not successful.
    Thx,

Maybe you are looking for

  • How do I print standard 6 3/4" standard size envelopes from an hp 8600 officejet pro printer?

    How do I print 6 3/4" standard size envelopes from an hp 8600 officejet pro printer. This printer has this size on the tray and has this size listed in the printer set up on the printer, but the drop down boxes from my computer to set up the printer

  • Mac Mini Server won't load Profile Manager

    My Mac Mini Server has stopped loading Profile Manager in a web browser, and gives me the following message: Caught exception "Connection to DB failed" [CSDatabaseError] executing route /auth/?redirect=https://stormforce.no-ip.biz/devicemanagement/ap

  • BPM and IDoc

    Hi all, we have set up a scenario where an IDoc is the trigger for a Business Process which then sends an IDoc to another system. Unfortunately this Business Process is not beeing triggered! Has anyone succeeded in starting a similar process???

  • Merging PC and Mac Libraries

    Hi, I have two libraries as follows that I would like to merge: 1. A 60GB library on a Windows PC that I have spent many, many, many hours getting the genre, track names, album art etc. corrected. This library does in fact sit on an external hard dri

  • Temporarily disabling opacity layer property - Feature Request

    Hi. I have searched but not found any answer in the After Effect's keyboard shortcuts page. Is there an easy way to disable the opacity effect layer property for one layer in a comp ? (temporarily, removing all the opacity keys is not an option) I'm