[Advanced-java] Strings

Singh, Shiv P. ssingh4 at telcordia.com
Tue Jul 1 15:58:07 2003


The output looks fine from the information what you have provided. 

The following method always will return -1 for the string you are testing
with as it does not contain "."

  loc.indexOf(".") == -1


-----Original Message-----
From: John Wilson [mailto:tug@wilson.co.uk] 
Sent: Tuesday, July 01, 2003 9:23 AM
To: Marco Ferretti; advanced-java@lists.xcf.berkeley.edu
Subject: Re: [Advanced-java] Strings 


Marco Ferretti wrote:
> Hi all guys... I have an xfile for you ...
> Assume this code :
> ....
>             String loc = currPathLocation.toLowerCase();
>             String fs = System.getProperty("file.separator");
>             fs = ""+fs.charAt(0);
>             System.out.println("fs = " + fs);
>             System.out.println("loc = " + loc);
>             if(!loc.endsWith(fs)){
>               loc += fs;
>               System.out.println("loc + fs = " + loc);
>             }
>             loc +=name;
>             System.out.println("name = " + name);
>             System.out.println("loc + name  = " + loc);
>             if (loc.indexOf(".") == -1) {
>               loc = loc + ".sid";
>               System.out.println("loc+ \".sid\" = " + loc);
>             }
> ....
> How can this output come out ?
>
> fs = \
> loc = c:\tmp\sid\models
> loc + fs = c:\tmp\sid\models\
> name = F2HX
>
>
>
> loc + name  = c:\tmp\sid\models\F2HX
>
>
>
> loc+ ".sid" = c:\tmp\sid\models\F2HX
>
>
>                                                         .sid


It would be helpful if you told us what you expected to see as the output.

The varaible 'name' would seem to contain "F2HX\r\n\r\n". As you don't show
us how you got name I don't think I can help much further. Try calling doing
name = name.trim().
John Wilson
The Wilson Partnership
http://www.wilson.co.uk

_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java