本文将介绍如何使用 Java 的 substring() 方法从字符串中提取特定子字符串。

示例代码:

String str = '78780B23C0012204000100084ABA0D0A';
String subStr = str.substring(5, 8);
System.out.println(subStr);

输出结果:

B23

解释:

  • str.substring(5, 8) 方法从字符串 str 中提取索引 5 到 8 之间的子字符串(不包括索引 8)。
  • 因此,输出结果为 B23

结论:

substring() 方法是一个强大的工具,可以用于从字符串中提取特定的子字符串。它在字符串处理和操作中非常有用。

Java String substring() 方法示例:提取特定子字符串

原文地址: https://www.cveoy.top/t/topic/qxUz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录