Results 1 to 9 of 9
  1. #1
    debz is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Unhappy comparing strings in notebook to names of a file

    Hi

    I'm having some trouble getting a list of numbers all ending with "|" from notepad to compare with names of files, that then need to be taken to be put in a folder if the match is true, can anyone help please???

    I have been trying to use a for loop to compare each number in the string from notepad up until "|". but i can't seem to get it to compare with the names of the file


    I need help!!!!

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default code please ...

    Please post the code of what you have tried so far.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    debz is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Question

    This is the last one that i have tried, i kept deleting and changing bits so i don't think i helped myself.
    Compare

    for (int i = 0; i < text.length; i++)//get each number
    if (X==Y)//compare 1st num in notepad to 1st number in file name.
    Compare;//if it matches go back and compare next number
    else //if it doesn't

    for( list=0; list < file.length;list++) //move to next file name until last file
    compare; start comparing next file name

    else//when it is end of the file list

    for(list2=0; list2< string.length; list2++); move down list in notepad
    compare; //start compare again for next string of numbers in notepad

    else

    System.println("no match");

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Next time post in CODE tags please.
    Java Code:
    for (int i = 0; i < text.length; i++)//get each number
    if (X==Y)//compare 1st num in notepad to 1st number in file name.
    [COLOR="Red"]Compare[/COLOR];//if it matches go back and compare next number
    else //if it doesn't
    
    for( list=0; list < file.length;list++) //move to next file name until last file
    [COLOR="red"]compare[/COLOR]; start comparing next file name
    
    [COLOR="red"]else[/COLOR]//when it is end of the file list
    [COLOR="red"]// you cant have an else without an if[/COLOR]
    for(list2=0; list2< string.length; list2++)[COLOR="red"];[/COLOR] move down list in notepad
    [COLOR="red"]compare[/COLOR]; //start compare again for next string of numbers in notepad
    
    [COLOR="red"]else[/COLOR]
    [COLOR="red"]// you cant have an else without an if[/COLOR]
    System.println("no match");
    Full of errors. One of the loops does nothing because theres a semicolon right after, and theres alot of elses with no corresponding ifs. Also, put braces on your loops, ifs and elses.
    And What is compare; (you spelled it differently some times). If it is a method it would be compare(the arguments);..
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #5
    debz is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default

    ok, Yes compare is supposed to be the method that i go back to with the next number and start again. thanks for the tips. I will try again, hopefully with less errors.

  6. #6
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Your welcome.. Make sure to look at everything I put in red, and add braces to the ifs elses and loops, and then post new code in CODE tags.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    The code you posted is part of the code or is all of the code?
    Java Code:
    if (X==Y)//compare 1st num in notepad to 1st number in file name.
    Have you opened and read the notepad file ?
    Have variables X and Y been stated and initialized?

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    debz is offline Member
    Join Date
    Feb 2009
    Posts
    4
    Rep Power
    0

    Default is this any better??

    Java Code:
    Public Class CallLog
    {
    
    Public Static Void Main (String args[])
    
    {:confused:
    
    File notepad = new File("callLog.text"); 
    FileInputstream fis = new FileInputstream (notepad); 
    DataInputstream dis = new DataInputstream (bis);
    File messages = new File("ITSuppLogDone.txt"); 
    FileInputstream fis = new FileInputstream (messages); 
    DataInputstream dis = new DataInputstream (bis);
    
    String record = null; 
    
    try { 
    
       while ( (record=dis.readLine()) != null ) 
    	{
    Compare (x,y)
    {
    
    for (int i = 0; i < text.length; i++)//get each number
         if (X==Y)//compare 1st num in notepad to 1st number in file name.
    {
         Compare;//if it matches go back and compare next number
    }
    	else //if it doesn't
    	{
    	
    	for( list=0; list < file.length;list++) //move to next file name until last file
    	if (!endofFile)
    	{
    	compare; //start comparing next file name
    	}
    
    	else//when it is end of the file list
    	{
    	for(list2=0; list2< string.length; list2++)// move down list in notepad
    	compare; //start compare again for next string of numbers in notepad
    } catch (IOException e) { 
        
       System.out.println("There are no matches");
       
    }  
    
    }
    }
    }

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default oh boy...

    You haven't tried to compile this code, have you? I really don't know where to start. There are too many beginers errors in the code to even start to correct it. For example, the case (upper and lower) of letters of words in Java is very important:
    Java Code:
    [B][COLOR="Red"]P[/COLOR][/B]ublic [COLOR="red"][B]S[/B][/COLOR]tatic [B][COLOR="red"]V[/COLOR][/B]oid [COLOR="red"][B]M[/B][/COLOR]ain (String args[])
    This should be:
    Java Code:
    [B][COLOR="Blue"]p[/COLOR][/B]ublic [COLOR="blue"][B]s[/B][/COLOR]tatic [B][COLOR="blue"]v[/COLOR][/B]oid [COLOR="blue"][B]m[/B][/COLOR]ain (String args[])
    It is obvious that you don't know what you're doing because you don't have the basics. I would kindly and strongly suggest that you study a good Java programming book. Also the following link is a very good help:

    The Java™ Tutorials

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. comparing strings
    By diggitydoggz in forum New To Java
    Replies: 7
    Last Post: 12-23-2008, 05:40 AM
  2. Problem Comparing Strings (its not what you think)
    By hilather in forum New To Java
    Replies: 7
    Last Post: 11-19-2008, 07:43 PM
  3. Comparing Strings
    By souFrag in forum Advanced Java
    Replies: 5
    Last Post: 05-21-2008, 10:03 AM
  4. JSTL -- Comparing two strings for equality
    By trinkets in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-12-2008, 05:39 PM
  5. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:44 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
  •