java.util.Scanner.findInLine(String pattern) 方法试图找到从指定字符串构造的模式在未来发生,在忽略分隔符。
声明
以下是java.util.Scanner.findInLine()方法的声明
public String findInLine(String pattern)
参数
-
pattern -- 一个字符串,指定要搜索的模式
返回值
此方法返回匹配指定模式的文本。
异常
-
IllegalStateException -- 如果此scanner已关闭
例子
下面的示例演示java.util.Scanner.findInLine()方法的用法。
package com.yiibai; import java.util.*; public class ScannerDemo { public static void main(String[] args) { String s = "Hello World! 3+3.0=6"; // create a new scanner with the specified String Object Scanner scanner = new Scanner(s); // find a string "World" System.out.println("" + scanner.findInLine("World")); // print the rest of the string System.out.println("" + scanner.nextLine()); // close the scanner scanner.close(); } }
让我们来编译和运行上面的程序,这将产生以下结果:
World ! 3+3.0=6