Results 1 to 4 of 4
  1. #1
    JJay84 is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default How to compare the String with integer

    I try to write a program that can detect the https in the JTextField. However, some problem is bordering me.
    How to comparing the String and Integer in If statement?

    [Code
    public void actionPerformed(ActionEvent evt) {
    String text = textField.getText();
    textArea.append(text + newline);
    textField.selectAll();

    String link="https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?";
    Pattern pattern = Pattern.compile(link,
    Pattern.CASE_INSENSITIVE | Pattern.DOTALL |Pattern.MULTILINE);
    Matcher myMatcher = pattern.matcher(text);
    while (myMatcher.find()) {

    if (link>1)
    {
    JOptionPane.showMessageDialog(null,"URL Links!!!");
    }
    }
    Code]

    The If statement I want to write is,
    when URL links have been detected more than 1 time,
    a dialog window will pop out and JTextField will inactive at the moment.
    Last edited by JJay84; 04-08-2011 at 09:09 AM.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

  3. #3
    JJay84 is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Sorry, what you mean?
    are u saying that matcher can be use to compare the string with the integer?

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Sorry This link is break.
    I mean about Matcher#groupCount() method, which can to returns the number of capturing groups in this matcher's pattern.
    You can not to use loop in this code. for example
    Java Code:
    if (matcher.groupCount > 0) {
    //to make something
    }
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. Replies: 8
    Last Post: 02-22-2014, 09:06 AM
  2. How compare two String?
    By artemff in forum New To Java
    Replies: 8
    Last Post: 08-29-2011, 09:00 AM
  3. cannot compare string
    By hmcoder in forum New To Java
    Replies: 1
    Last Post: 01-19-2011, 04:57 PM
  4. Why we use String compare to String Buffer
    By Sharath_Forums in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 07:21 AM
  5. String Compare not working
    By Revelation in forum New To Java
    Replies: 3
    Last Post: 06-30-2007, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •