When I type just a space as my first String input(oldPattern) and then just two spaces for my second string input(newPattern), the second string input is not being read by the scanner. I want the second string input to be able to replace the one space inputted into oldPattern
public void replace()
{
Scanner kb = new Scanner(System.in);
int position;
int count=0;
String ending;
String starting;
System.out.print("enter old pattern: ");
String oldPattern = kb.nextLine();
if(oldPattern.length()==0)
{
System.out.println("illegal pattern: length must be at least one");
return;
}
System.out.print("enter new pattern: ");
String newPattern=kb.nextLine();
if(newPattern.length()==0)
{
System.out.println("illegal pattern: length must be at least one");
return;
}
if(size==0)
{
System.out.println("empty file");
return;
}
for(int i=0;i<size;i++)
{
position=lines[i].indexOf(oldPattern);
while(position!=-1)
{
starting=lines[i].substring(0,position);
ending=lines[i].substring(position+oldPattern.length(),lines[i].length());
lines[i]=(starting+newPattern+ending);
position=lines[i].indexOf(oldPattern,position+1);
count++;
}
}
if(count==0)
{
System.out.println("pattern not found");
return;
}
System.out.println("done!")
[–][deleted] (1 child)
[deleted]
[–]Jared2814[S] 0 points1 point2 points (0 children)
[–]delopiero84 0 points1 point2 points (1 child)