0
我有以下一組字符串。替代從索引到開始和結束標記的String.subSequence
String s1 = "Some random text followed by timestamp('some data')";
String s2 = "Some extended random tet followed by timestamp('some extra data')";
String s3 = "Some tiny random text followed by timestamp('some tiny data')";
我希望替換與timestamp('
開始,以')
結束序列。 我知道下面的string.subSequence(beginIndex, endIndex)
會使用開始和結束標記從字符串中獲得一個子字符串。但就我而言,我不能只給它開始和結束索引,因爲它可以是動態的。
我期待爲這樣的事情,
string.functionIAmLookingFor(String startCharSequence , String endCharSequence);
如果在字符串中發現兩個charSequences,要麼返回字符串是在開始和結束標記,或排除該字符串的字符串之間,或任何其他格式。我正在使用Java 7.任何幫助將不勝感激。
你應該看看['的indexOf()'](https://docs.oracle.com/javase/7/docs/api /java/lang/String.html#indexOf(java.lang.String))。 –
[正則表達式](https://docs.oracle.com/javase/tutorial/essential/regex/)可以解決這個問題 –
@FlorentBayle:感謝的人,我感到愚蠢的是我自己沒有明確自己,而我太忙了進入一些本地功能:) –