[Advanced-java] Strings

John Wilson tug at wilson.co.uk
Tue Jul 1 14:30:23 2003


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