Page 3 of 10 FirstFirst 12345 ... LastLast
Results 41 to 60 of 186
  1. #41
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    Which is what I was saying, almost from the beginning...

    Except that they seem to want the stuff between the open (ie "<@dynamichtml @>") and close (ie "<@end@>") markers, which are on separate lines. As well as the bit in the first marker.

    I know how to do it, but I'm not going to code dump here.

    And I did say someone would do a regex for it...:)
    I think my code is enough spoonfeeding; I hate it when the requirements sort of organically evolve (here in +- 40 replies). In the end this is going to be a question about XML where the XML is not well formed. I go back to lurking for this thread ;-)

    kind regards,

    Jos

  2. #42
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Would Something along this line not work

    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    while ((line = br.readLine) != null) {

    public class CaptureResource {
    public static void main(String[] args) {
    String ResourceVal = "<@dynamichtml+"(.*)"+@>"
    {

    }

    }
    } catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    } finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }

  3. #43
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nickrowe_2k View Post
    Hi JosAh will that work with the code from earlier for reading in a file? Im only asking as I dont know anything about regex.

    Also in your code, please correct me if im wrong you have created a class that searches for the beginning and end of a string using a wild card?

    you are then printing out,

    System.out.println(find("<@dynamichtml", "@>", "This is <@dynamichtml foo @>; so there"));
    System.out.println(find("<@dynamichtml", "@>", "This isn't <dynamichtml foo >; so there"));

    so where are "<@dynamichtml", and "@>" defined within the string variables "beg" & "end" and also where does the value between them "unknown string" print out.

    regards Nick
    It prints out the result of the find( ... ) method which is either null (nothing found) or the text between those two marker Strings. The two marker Strings are passed to the find( ... ) method as parameters so that method can use any two markers.

    kind regards,

    Jos

  4. #44
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    lol Guys they dont want anything back from the "@end@"

    Literally just the resource name so from <@dynamichtml TimeLineManager_resource@>
    All they literally want it "TimeLineManager_resource" nothing else.
    As i mentioned there are several resources so i cannot just write an exact string to capture and print out the one value.

    Its literally just the name ignore all the other stuff. Everything needed is on one line.

  5. #45
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nickrowe_2k View Post
    Its literally just the name ignore all the other stuff. Everything needed is on one line.
    Well, use my method then; nothing more is needed.

    kind regards,

    Jos

  6. #46
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Sorry i know im asking alot of questions and i really REALLY do appreciate everyones time helping with this because honestly I'd be in a mess without your help. Still can't believe I got this dumped on me with no experience in JAVA.

    But in your print statement, just so im understanding you've put, so we're finding the value between "<@dyanmichtml" & "@>" but then we have This is <@dynamichtml foo@>;so there"???

    The idea is that basically I need to find and store the variable in some sort of auto array not print it as im going to loop the process for each line until the end of the document.


    In short

    Capture value between beginning and end for that line
    store value in array
    loop to next line and repeat process until
    end of document
    then
    sort array (ascending)
    print array

    regards Nick
    Last edited by nickrowe_2k; 05-20-2010 at 03:27 PM.

  7. #47
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nickrowe_2k View Post
    But in your print statement, just so im understanding you've put, so we're finding the value between "<@dyanmichtml" & "@>" but then we have This is <@dynamichtml foo@>;so there"???
    That was just a test String to show that the method works. You can pass any delimiting tag Strings and a String to be searched to that method. You don't need a separate class for it: just copy and paste the code of the method to anywhere you like.

    kind regards,

    Jos

  8. #48
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nickrowe_2k View Post
    In short

    Capture value between beginning and end for that line
    store value in array
    loop to next line and repeat process until
    end of document
    then
    sort array (ascending)
    print array
    You're almost there: keep reading lines from your input stream, feed it to my method and if the result of that method isn't null (it found something then) add it to an ArrayList<String> (not an array!). When your loop has finished (nothing more to read) make the Collections.sort( ... ) method sort the list and voila.

    kind regards,

    Jos

  9. #49
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    So putting together what I have so far currently im reading the file and finding a line containing the details of my string and returning a value thats contained within AWESOME.

    As I mentioned previously the theory im well with its just the way Java reads to me compared to other languages that is puzzling me. For only looking at it yesterday its getting a bit clearer thanks to you guys. Seriously im sure when you first looked at a new language and were like ??? haha ok ...google :)

    Apologies regarding leaving that blank class in there I actually miss-read I wasn't intentionally doing that lol, it would be a bit pointless lol
    ------------------------------------------------------------------------------------------------------------------------

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    while ((line = br.readLine) != null) {


    public static String find(String beg, String end, String line) {

    Pattern p=Pattern.compile(beg+"(.*)"+end);
    Matcher m= p.matcher(line);

    return m.find()?line.substring(m.start(1), m.end(1)):null;


    }
    public static void main(String[] args) {

    System.out.println(find("<@dynamichtml", "@>", "This is <@dynamichtml foo @>; so there"));
    System.out.println(find("<@dynamichtml", "@>", "This isn't <dynamichtml foo >; so there"));

    }
    }
    catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    }
    finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }
    Last edited by nickrowe_2k; 05-20-2010 at 04:42 PM. Reason: miss read

  10. #50
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    That doesn't make any sense syntactically: you can't define a class Find in the middle of a while-loop body and you don't need another class. Your original class should look like this:

    Java Code:
    public class YourClass {
       public static String find( ... ) { ... }
       public static void main( ... ) { ... }
    }
    The first method is my method, the main( ... ) method is your responsibility. You call my method somewhere in the body of your while-loop.

    kind regards,

    Jos

  11. #51
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,173
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    I think my code is enough spoonfeeding; I hate it when the requirements sort of organically evolve (here in +- 40 replies). In the end this is going to be a question about XML where the XML is not well formed. I go back to lurking for this thread ;-)

    kind regards,

    Jos
    "not well formed XML" is just text.
    Like a java class that doesn't compile.
    :)

  12. #52
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Smile

    So basically I've been looking into some more online code from various site examples finding supposedly more Java librarys i need to import regarding my array and imput stream etc.

    I believe i have initiated an array list within the find class to add the (wild card string) between the string of "<@dynamichtml" and "@>" then I have created an else if its then end of the document (which im not sure how to do yet) sort and print out the array.

    else find next line and repeat the process.

    regards Nick

    import java.io.BufferedReader;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.io.InputStreamReader;

    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    while ((line = br.readLine) != null) {
    public class Find {

    public static String find(String beg, String end, String line) {

    Pattern p=Pattern.compile(beg+"(.*)"+end);
    Matcher m= p.matcher(line);
    return m.find()?line.substring(m.start(1), m.end(1)):null;
    System.out.println(" - Storing String(.*)");
    ArrayList arrayList = new ArrayList();
    listA.add(".*");

    else if {
    *\
    ** end of document
    *\
    public static void main(String[] args) {

    Collections.sort(ArrayList);
    System.out.println("New Sorted List : " + ArrayList);
    System.out.println();
    }

    else {

    public static String find(String beg, String end, String line) {

    Pattern p=Pattern.compile(beg+"(.*)"+end);
    Matcher m= p.matcher(line);
    return m.find()?line.substring(m.start(1), m.end(1)):null;
    System.out.println(" - Storing String(.*)");
    ArrayList arrayList = new ArrayList();
    listA.add(".*");
    }

    }
    } catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    } finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }
    Last edited by nickrowe_2k; 05-20-2010 at 05:53 PM. Reason: update

  13. #53
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,173
    Rep Power
    20

    Default

    Is this all your code?
    I'm asking because it's really not Java at all.

    You might be well served to have a look at the Sun (now Oracle) tutorials, and run through the basics to at least get the structure of the code correct.

    ETA: and you keep forgetting to put your code in code tags.

  14. #54
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Hi guys, thanks to Tolls for the link, i was finding some links to suns site before but they were pants, the url you suggested seems a bit more descriptive and useful, thank you for that.

    Im still puzzled as to where I should include my else if. As for tags im not sure what I've missed, please let me know and i'll correct myself.


    //import java librarys
    import java.io.BufferedReader;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.io.InputStreamReader;

    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    //read from html file
    while ((line = br.readLine) != null) {
    //initiate loop
    public class Find {
    //class to find string

    public static String find(String beg, String end, String line) {

    Pattern p=Pattern.compile(beg+"(.*)"+end);
    Matcher m= p.matcher(line);
    return m.find()?line.substring(m.start(1), m.end(1)):null;
    System.out.println(" - Storing String(.*)");
    ArrayList arrayList = new ArrayList();
    listA.add(".*");
    }
    //where should I add my else if statement & how to I check for the end of the file?

    public static void main(String[] args) {
    //main body to sort array and print
    Collections.sort(ArrayList);
    System.out.println("New Sorted List : " + ArrayList);
    System.out.println();

    }
    }
    }
    catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    } finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }

  15. #55
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    ETA: and you keep forgetting to put your code in code tags.
    While you're at it: also please don't read what I wrote in my reply #50.

    kind regards,

    Jos

  16. #56
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    //import java librarys
    import java.io.BufferedReader;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.io.InputStreamReader;
    //class to find & capture string then copy instance to array
    public class Find {
    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    //read from html file
    while ((line = br.readLine) != null) {
    //While loop to capture value between string, return value and create and store in array

    public static String find(String beg, String end, String line) {


    Pattern p=Pattern.compile(beg+"(.*)"+end);
    Matcher m= p.matcher(line);
    return m.find()?line.substring(m.start(1), m.end(1)):null;
    System.out.println(" - Storing String(.*)");
    ArrayList arrayList = new ArrayList();
    listA.add(".*");

    }

    public static void main(String[] args) {
    //main method to sort array and print as
    Collections.sort(ArrayList);
    System.out.println("New Sorted List : " + ArrayList);
    System.out.println();
    }
    }
    }
    catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    }
    finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }
    }
    Last edited by nickrowe_2k; 05-21-2010 at 11:38 AM. Reason: Tidying Up, Apologies for the delay

  17. #57
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Glueing pieces of code together and hoping that it works is like putting a bunch of monkeys behind keyboards and hoping for a literary masterpiece. Reread my replies #48 and #50 and think what that return statement is doing in the middle of your while loop; your code is a mess.

    kind regards,

    Jos

    ps. why do you refuse to put your code in [code] ... [code] tags? Are you cabable to program in any other language? If not, notify your boss that you can't do this.

  18. #58
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Yes i've done various other types I just find Java quite frustrating, in any other program I've seen in various examples i've not seen reference to any [Code]..[CODE] or <code> ...</code> tags.

    also with regards to the loop im looking at examples of similar running programs with while loops calling methods within a class etc and have simply been basing it on that. As i was saying earlier im understanding the method programming wise im just not understanding the way in which i need to put it together.

    I really do appreciate all the guidance but as I said this is entirely new to me, I dont intend to give up, its just highly frustrating lol.
    Apologies as I know you must be looking at it like ???? seriously what are you doing lol. but for me im looking at examples and basing the structure in a similar way.

    regards Nick

  19. #59
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Take a break from looking at examples and go through Oracle's tutorial to learn the basic concepts required to write correct Java programs. You will save much more time that way (both yours and others).

  20. #60
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nickrowe_2k View Post
    Yes i've done various other types I just find Java quite frustrating, in any other program I've seen in various examples i've not seen reference to any [Code]..[CODE] or <code> ...</code> tags.
    That is not a Java thing, it's a forum thing (most if not all forums use those tags). It improves readability and leaves your indendation (if any) alone. btw, please do reread my replies #48 and #50 and leave my find method intact; there is no reason to chop it up beyond recognition. That method is supposed to find a String in another String; it doesn't want to do with file reading or anything else.

    kind regards,

    Jos

Page 3 of 10 FirstFirst 12345 ... LastLast

Similar Threads

  1. How can I include a html file in html textarea?
    By surya_dks in forum New To Java
    Replies: 2
    Last Post: 10-04-2008, 08:20 AM
  2. get data from servlet to html
    By lema in forum Java Servlet
    Replies: 7
    Last Post: 05-22-2008, 05:00 PM
  3. get data from html to servlet
    By lema in forum Java Servlet
    Replies: 66
    Last Post: 04-09-2008, 03:43 PM
  4. Replies: 0
    Last Post: 04-04-2008, 10:36 AM
  5. how to upload a file along with html form data
    By pranith in forum Java Servlet
    Replies: 3
    Last Post: 07-30-2007, 03:33 AM

Posting Permissions

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