【发布时间】:2010-12-22 07:17:48
【问题描述】:
String input0 = "G1 and G2 are the founders of Microsoft.";
String input1 = "The swimming medals were won by G1 and G2";
我想解析上面的字符串并创建2个单独的数组(注意:G1、G2、G3、...是用户输入的占位符,想单独获取它们)
e.g. for input0 the following arrays should be created array0 [G1, G2] and array1 [" and ", " is the founder of Microsoft."]
e.g for input1 the following arrays should be created array0 [G1, G2] and array1 ["The swimming medals were won by ", " and "]
我尝试过使用indexOf 函数和split,但到目前为止还不能正常工作。
【问题讨论】:
-
无论您如何表示数据,正则表达式都是获取 g1 和 g2 的最简单方法。
-
很想知道这个的真正用例是什么!
-
@Pangea 我正在寻找用户在标有关键字 G1、G2、... 的位置提供输入,以便我可以在用户界面中使用输入文本框显示此内容。我的目的是找出需要多少动态输入,并在渲染这些文本框之前或之后添加字符串的其余部分。
标签: java