当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.util.Scanner.findInLine()用法及代码示例



描述

这个java.util.Scanner.findInLine(String pattern)方法尝试查找从指定字符串构造的模式的下一次出现,忽略分隔符。

声明

以下是声明java.util.Scanner.findInLine()方法

public String findInLine(String pattern)

参数

pattern- 指定要搜索的模式的字符串

返回值

此方法返回与指定模式匹配的文本。

异常

IllegalStateException- 如果此扫描仪已关闭

示例

下面的例子展示了 java.util.Scanner.findInLine() 方法的用法。

package com.tutorialspoint;

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

相关用法


注:本文由纯净天空筛选整理自 Java.util.Scanner.findInLine() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。