JTextArea methods + String Handling

Hi There,
My Question was, that i have made a small text editor application, and i was hoping that some one could tell me how to add the text, which is opened in a JTextArea to a Vector (or another data structure if this is more appropriate), which i can then parse using Regular expressions??
Also, could u point me in the direction of a resource that has examples of how to use regular expressions in java 1.4 (util.regex)?
Thanks in advance,
much appreciated!

I'd use getText() and put the text in a String, like the previous poster said. From there you can parse the string using the Pattern and Matcher objects.
Here's a link that has some examples of regular expressions:
http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/

Similar Messages

  • Concerning String Handling

    Hello To Every One,
    I have a query concerning String Handling.
    String s3 = "Java is a wonderful language";
        System.out.println("s3 is: "+s3);
        System.out.println("lastIndexOf(a, 23) = " + s3.lastIndexOf('a', 23));
        System.out.println("********");
    String s4= "Java is a wonderful language";
        System.out.println("s4: "+s4);
        System.out.println("lastIndexOf(a, 19) = " + s4.lastIndexOf('a', 19));Output is:
    s3 is: Java is a wonderful language
    lastIndexOf(a,23)=21
    s4 is: Java is a wonderful language
    lastIndexOf(a,19)=8what is basic difference in s3.lastIndexOf('a', 23)); and
    s4.lastIndexOf('a', 19));
    that output is lastIndexOf(a,23)=21 and
    lastIndexOf(a,19)=8
    Please clarify..
    Thanks.

    Even without reading the API you should be work out what it is doing
    - by reading the source code for the method.
    - debugging it with a debugger.
    - inferring what it does from its name.
    But reading the API is the most obvious, that what the documentation is for.

  • Error in Raising exceptions in a method and handling the same in the WF

    Hi All
    I tried to implement Raising exceptions in a method and handling the same in the workflow
    in the same way given in SAPtechnical site .
    1.by adding a error msg in exception parameter .
    2. if the select query fails, to fetch the agent then :exit_return 9001 'ztable name' space space space.
    3.in the Background activity in which this method is called there automatically one outcome appears ,and I hav acitvated that outcome and in that done what need to be done for that error handling - just send a mail to concern person .
    4. in the normal outcome of the activity , the step to be executed are there .
    but its not working , if exception come then the WF stuck there only . it do not follow the exception outcome .
    Kindly help me , How can I do the exception handly in WF.
    thanks & Regards
    Kakoli

    > That is usually the case - you catch an error in the underlying program and pass that back so the workflow can go into error.
    > You're doing it correctly.
    I don't think that's quite right.
    If you define an error/exception in a method, it is automatically mapped to an outcome of the step/task.
    If you activate that outcome, then you can handle the exception in a branch of the workflow.
    For example: 'Remote connection is down, please contact Basis'
    The step should only go into error if an outcome occurs that you have NOT activated.
    So the original question is valid. Please give some more information on what the error message is..
    chrs
    Paul

  • What method replace handler(before jheadstart 9.0.5.1) in jheadstart 10.1.2

    What method replace handler(before jheadstart 9.0.5.1) in jheadstart 10.1.2.0.
    Does anybody tell me how to do it ?
    Thanks for your help.

    The handler layer as provided in JHeadstart before ADF existed, has now been replaced with ADF databinding layer. Whereas in the pre-ADF days, you would add custom methods to JHeadstart handlers, you now add these methods to the application module impl class, and then you can drag and drop these methods onto your page or struts action. The ADF binding layer will ensure that your method gets called correctly.
    You might want to check the following link with more info on adf data binding:
    http://www.oracle.com/technology/products/jdev/collateral/papers/10g/ADFBindingPrimer/index.html
    Steven Davelaar,
    JHeadstart Team.

  • Difference between method,event handler,supply function.

    hi,
    i wants to know what is the difference between
    method.
    event handler.
    supply funciton.
    Regards:
    Pankaj Aggarwal

    Hi Pankaj,
    These are few lines from the F1 help documentation given,
    Web Dynpro: Method Type :The type of a method defines whether you have an event handler, a supply
                                                function, or a (normal) method.
      Event Handler : Handlers of an event, a controller, an action, or an inbound plug of a view.
       Method : Modularization unit within a view or a controller.Methods of a view can only be called locally
                       within this view.Methods of a controller (component or custom controller) can also be called from
                       a view or another controller, provided the controller is entered as controller used .
       Supply Function : Method for filling a context node.
    For more information refer to the Thomas post
    Regards,
    Sravanthi

  • How to Convert JTextArea to String

    How would i convert JTextArea to string?

    elaborate, whats RTFAPI? I searched for it and got
    nothing.Since I'm not quite sure if you are being sarcastic, that translates to "read the f*cking application programmer interface". :)

  • JTextArea.setText("String ") not updating the GUI.

    Hi,
    When i tried to update the JTextArea with a new String it is not replacing the string in the TextArea.
    If I try to print the content by retrieving the data in the TextArea using JTextArea.getText() it is showing the latest string set to the JTextArea.
    What might be the problem?
    DP

    Here is the code. I am calling the displayMessage() from onMessage() method.
    private void displayMessage(String str){
         textArea.setText(str);
         textArea.revalidate();
         System.out.println("Message Received from QUE: "+ textArea.getText());
    public void onMessage(Message msg) {
    try {
    if (msg instanceof TextMessage) {
         msgText = ((TextMessage)msg).getText();
    } else {
         msgText = msg.toString();
         msgText = msgText.trim();
    System.out.println(msgText );
    displayMessage(msgText);

  • Question on JTextArea.append(String str)

    Hi All,
    When i provide JTextArea.append("FMTL") it is showing me on the JTextArea but when i give it as
    String item="Viswanadh";
    JTextArea.append(item).this particular statement is remaming blank on the TextArea.
    Any idea why this is happening and is there any other method to be used instead of append.???
    Thanks in advance..
    regards,
    Viswanadh

    class OnApplyFormat implements ActionListener{
         public void actionPerformed(ActionEvent formatevent){
              JComboBox source = (JComboBox) formatevent.getSource();
                   String item =  source.getSelectedItem().toString();
                     System.out.println("Selected Format is:"+item);
                     try
                       if ( item!=null )
                              System.out.println("Format is:"+item);
                     infoarea.append("FMTL");
                   infoarea.append(item);
                     infoarea.append("\r\n");
                   infoarea.append("FMTU");
                   infoarea.append("\r\n");
                   infoarea.append("wait 5");
                   infoarea.append("\r\n");
              else
                   throw new Exception("FormatNotFoundException");
                          }catch(Exception e){
                          e.printStackTrace();
    }That is my code and still i am facing the same FMTL is not getting appended with the item variable.
    Help me in solving this issue.
    Thanks in advance.
    regards,
    Viswanadh

  • Tokenizing a JTextArea(how do i make the JTextArea a string?)

    I am working on this text analyzer program which is kinda like a replica of what you find when you a do a word count in many office suites. It tells you stuff like number of sentences, longest sentence, shortest sentence and average length. Number of words, longest shortest and average word length. In addtion there is a word search to it.
    It took me a good 3 hours to realize that there was such a thing as a panel and I could impliment this to add more than one object to a borderlayout section.
    I think I have figured out everything with the StringTokenizer part, well except for how do add it to an array. Someone mentioned something to me about an
    islist.StringTokenizer or something, but I haven't been able to find anything else on this.
    Right now, however, my primary concern is how can I take input from a JTextArea and be able to parse it with the StringTokenizer, which to the best of my knowledge has to be a string. It this as simple as a getValue(); type thing or do i have to add some sort of action listener that finds out when it changes or something?
    thank you for your time

    I just figued out the JTextArea thing
    it is JTextArea.getText();
    im stupid :P

  • How to get InputStream from JTextArea.getText() string?

    hello,
    well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
    thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
    FileWriter fw = new FileWriter ("text.txt");
    fw.write(editField.getText());  // editField is my JTextArea instanceso i thought of doing smth like this
    String lineSeparator = System.getProperty("line.separator");
    // somehow getting the InputStream for my editField and save it in "is"
    BufferedReader br = new BufferedReader(new InputStreamReader (is));
    String line;
    while ((line = br.readLine()) != null) {
    fw.write(line);
    fw.write(lineSeparator);
    }

    pSaiko wrote:
    hello,
    well the postname pretty much says it, i need to get an InputStream for the String of a JTextArea.
    thing is, i want to save the string in a textfile, but the new line isnt recognized when i write it to the file.
    FileWriter fw = new FileWriter ("text.txt");
    fw.write(editField.getText());  // editField is my JTextArea instanceso i thought of doing smth like this
    String lineSeparator = System.getProperty("line.separator");
    // somehow getting the InputStream for my editField and save it in "is"
    BufferedReader br = new BufferedReader(new InputStreamReader (is));
    String line;
    while ((line = br.readLine()) != null) {
    fw.write(line);
    fw.write(lineSeparator);
    This is very simple, it isn't buffered, but it should work for you.
    Sting s = editfield.getText();
    for(int i=0; i<s.length();i++) fw.write((int)s.charAt(i));
    fw.flush();
    fw.close();

  • How can I get a method to handle the return type flexibly?

    I coded an abstract class implementing an abstract method called retrieve(int index). When I inherit from that class and add an implementation for that method I want to be able to return any primitive values as well as any objects. In effect the method should look like this in several child classes:
    public int retrieve(int index)
    for a child class handling ints, or this:
    public float retrieve(int index)
    for a child class handling floats, just as well as this:
    public Object retrieve(int index)
    for a child class handling objects.
    How do I have to define the abstract method to get this behaviour?
    Thx for all help, it's much appreciated!

    Yes, agreed - return Object.
    If you know you've got a class which can provide an
    int and are thus expecting an int, what you can do is
    provide a "retrieveInt()" method in that subclass
    (which would be simply "return ((Integer)
    retrieve()).intValue();") and call it via casting
    (you can cast, since if you're expecting an int then
    you know this class provides one, right?)
    If you don't know that you've got a class
    which can provide a primitive, then you won't be able
    to write the code to use that primitive anyway, so
    wanting to return them is barking up the wrong tree.
    Er - that "explanation" may be as clear as mud ;o)Good idea, but this is how it works right now. But instead of having a retrieveInt, retrieveFloat and so on, I'd like to have one method name for all occurances.

  • Doubt in String handling...

    Hi
    Here i have a code snippet.
    public class StringComp
         public static void main(String[] args)
              String a = "abc";
              String b = "def";
              String c = "abcdef";
              String d = "xyz";
              String e = "xyz";
              a+=b;
              System.out.println("Value of a = :" + a);
              System.out.println("Value of c = :" + c);
              System.out.println("Value of d = :" + d);
              System.out.println("Value of e = :" + e);
              if(a==c)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
              if(e==d)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
    if i compile and run this code snippet i am getting the result as
    Value of a = :abcdef
    Value of c = :abcdef
    Value of d = :xyz
    Value of e = :xyz
    FALSE
    TRUE
    here i add the value of a and b to a. so a=abcdef, value of c also abcdef.
    but if i check (a==c) the result is False why??
    Can anyone tell me how the string is handled in java (behind the scene) where they are stored ? and how the == operator works on String?
    thanks in advance
    chithrakumar

    Strings are pooled. This means that if you writeString a = "1";
    String b = "1";you have a good chance that a == b.
    For new Strings (as "abc" + "def" returns), the pool is bypassed. This explains why "abc + "def" != "abcdef". To make sure a String is pooled, use intern (). ("abc" + "def").intern () == "abcdef", guaranteed.
    This is all very opaque behaviour and you shouldn't really rely on this in your code, except in very rare circumstances (extreme performance concerns or if you're stuck with an identity hash map [not that that's very likely]).

  • Regular Expressions and string handling

    I'd like to be able to make a method that takes a String and removes certain substrings from that string. What I'm doing is that I'm getting some text from the internet (an HTML doc) and I'd like to remove all the tags from it.
    my method is:
         String DeTokenString(String s)
    String t=new String(s.replaceAll("<regex>",""));
              return t;
    What would I put in place of <regex> to remove all html tags? s has already had its leading and following whitespace removed elsewhere with .trim() before being passed to DeTokenString.
    Is there any other simple way to accomplish this?

    It does on whatever manages to get through my 17
    firewall, hand-woven packet destroyers, and
    titanium-lead armor.So! That is your final defense mechanism. Bwah hah hah hah hah! Now I have you. That was all I needed to improve my 17-firewall-sneaking-through, hand-woven-packet-destroyer-unweaving, titanium-lead-armor-piercing virus!
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Anybody have some unicode string handling code I could use?

    Text handling plugins are not working for some users, since Lua and Lr are not on the same page char-representation-wise.
    For example, if you enter
    À
    in Lightroom, it's getting interpreted as
    À
    in Lua.
    in non-plugin environment, one could just use slnunicode, however in plugin one needs pure lua solution.
    Anybody?
    ref: http://lua-users.org/wiki/LuaUnicode
    R

    Try
    Debug.pause( "uni-find", string.find( photo:getFormattedMetadata( 'title' ), 'À' ) )
    when title field has an 'À' in it.
    Instead of seeing the coordinates of the 'À' that is there, you'll see nil.
    PS - this code looks promising (?) found at http://forums.gaspowered.com/viewtopic.php?f=19&t=29879
       function conv2utf8(unicode_list)
          local result = ''
          local w,x,y,z = 0,0,0,0
          local function modulo(a, b)
             return a - math.floor(a/b) * b
          end
          for i,v in ipairs(unicode_list) do
             if v ~= 0 and v ~= nil then
                if v <= 0x7F then -- same as ASCII
                   result = result .. string.char(v)
                elseif v >= 0x80 and v <= 0x7FF then -- 2 bytes
                   y = (v & 0x0007C0) >> 6
                   z = v & 0x00003F
                   y = math.floor(modulo(v, 0x000800) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xC0 + y, 0x80 + z)
                elseif (v >= 0x800 and v <= 0xD7FF) or (v >= 0xE000 and v <= 0xFFFF) then -- 3 bytes
                   x = (v & 0x00F000) >> 12
                   y = (v & 0x000FC0) >> 6
                   z = v & 0x00003F
                   x = math.floor(modulo(v, 0x010000) / 4096)
                   y = math.floor(modulo(v, 0x001000) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xE0 + x, 0x80 + y, 0x80 + z)
                elseif (v >= 0x10000 and v <= 0x10FFFF) then -- 4 bytes
                   w = (v & 0x1C0000) >> 18
                   x = (v & 0x03F000) >> 12
                   y = (v & 0x000FC0) >> 6
                   z = v & 0x00003F
                   w = math.floor(modulo(v, 0x200000) / 262144)
                   x = math.floor(modulo(v, 0x040000) / 4096)
                   y = math.floor(modulo(v, 0x001000) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xF0 + w, 0x80 + x, 0x80 + y, 0x80 + z)
                end
             end
          end
          return result
       end
    or maybe this: (?)
    function unichr(ord)
        if ord == nil then return nil end
        if ord < 32 then return string.format('\\x%02x', ord) end
        if ord < 126 then return string.char(ord) end
        if ord < 65539 then return string.format("\\u%04x", ord) end
        if ord < 1114111 then return string.format("\\u%08x", ord) end
    end
    from http://stackoverflow.com/questions/7780179/what-is-the-way-to-represent-a-unichar-in-lua
    R

  • JTextField or JTextArea to string?

    I am a bit rusty on my Java and have recently been kinda reteaching myself it. I created an applet to write some HTML code. my first problem is that i can not figure out how to use the input in a JTextField or JTextArea as part of a StringBuffer. I have tried a couple different things and can't figure it out. my next problem is i am using JOptionPane's for an undertermined number of variables. is there some way to add an undertermined number of pane.add(). also, i need to beable to paste things into the input areas, is there some way to do it? thanks

    An important skill to have as a software developer is the ability to look up the API documentation.
    http://java.sun.com/j2se/1.4.2/docs/api/index.html (for 1.4.2 - substitute 1.5.0 in the URL for 1.4.2 for that version if you wish)
    For example, for JTextField, it would appear you'd need to simply invoke the getText() method to get the text contained therein.

Maybe you are looking for

  • Printing only 10 lines in the Report

    Hi, I have a unique requirement , need to customize the Existing cheque print report in that ,if there are 20 invoice lines related to cheque,i should only print first 10 lines in the output and in 11 th line display message as remaining lines are No

  • How do i delete the previous backups from HP surestore PD5000z?

    I have been using the HP PD5000z to backup my main hard drive for a couple of years. I now receive the error that the back up is too large and need to either reduce the files being backed up or delete files from the PD5000z. How do i know which files

  • How to determine the complexity of OBIEE report?

    Hi BI Gurus, We are currently planning to do OBIEE 11g upgrade. To do impact analysis, we have been asked to come with the complexity of all the reports which are now in OBIEE 10.1.3.4.2. I came up with the following points. 1) No. of tables used in

  • JFileChooser file name extention queistion

    hi i would like to know if it is possible to place a file extention in the filename section when you open the save dialog. So as when the user types a file name in the file extention is added automaticly to only allow the user to save in .png. My cod

  • Query with duplicates

    I have a query which basically returns one row (location ID) from the select which is shown below SELECT location_id FROM tasks WHERE container_id = :container_id AND task_id = (SELECT MIN(task_id FROM tasks WHERE container_id = :container_id) But my