StringUtil

public class StringUtil
extends Object

java.lang.Object
com.android.tradefed.util.StringUtil


用于转义字符串以进行常见字符串操作的实用工具类。

摘要

公共构造函数

StringUtil()

公共方法

static String expand(String str, Map<String, String> valueMap)

使用映射中的值展开给定字符串中的所有变量。

static String removeAnsiCodes(String coloredText)

移除所有常见的 ANSI 转义序列

公共构造函数

StringUtil

public StringUtil ()

公共方法

展开

public static String expand (String str, 
                Map<String, String> valueMap)

使用映射中的值展开给定字符串中的所有变量。

Map<String, String> valueMap = new HashMap<>() {
   put("FOO", "trade");
   put("BAR", "federation");
 };
 String str = StringUtil.expand("${FOO}.${BAR}", valueMap);
 assert str.equals("trade.federation");
 

参数
str String:要展开的源 String

valueMap Map

返回
String 包含变量名称和值的映射

removeAnsiCodes

public static String removeAnsiCodes (String coloredText)

移除所有常见的 ANSI 转义序列

参数
coloredText String:可能包含彩色文本的 ANSI 代码的字符串

返回
String 移除了所有 ANSI 代码的字符串