while causes Program to Stop  
Author Message
DarkPressure





PostPosted: Visual J# General, while causes Program to Stop Top

static String ExtractFilePath(String Path)
{
String VirtualString = String.Copy(Path);
int i = 0;
while (VirtualString.IndexOf("\\") > 0)
{
i = i + VirtualString.IndexOf("\\");
VirtualString.Remove(1, VirtualString.IndexOf("\\"));
}
return Path.substring(1, i);
}

This code cause my program to "suspend".
I don't get any Error returned.
I hope someone sees the problem

Thank you, DarkPressure


Visual J#10  
 
 
Kazuya Ujihara





PostPosted: Visual J# General, while causes Program to Stop Top

What you want to do is System.IO.Path.GetFileName(String path). Addtionally, it contains the other logical error. Execute the following code to know String.Remove(int) and refer String.LastIndexOf() method.



public static void main(String[] args)
{
String a = "123456";
System.out.println(a.Remove(3));
System.out.println(a);
}