2015-10-27 40 views
-2

我有一个字符串值串号范围治疗的Java

strValue1 = “-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-“; 

strValue2 = “-4-5-6-7-“; 

我想从strValue1得到只有我有范围strValue2

-4-5-6-7-

你能在这方面的帮助吗?

在此先感谢。

+0

你是什么意思_get_?你的意思是你想检查第一个是否包含第二个? –

+1

你的代码在哪里?你的输入和输出是什么? – Rehman

+0

我不明白这个问题。当你在s2中已经有了s1的时候,你为什么想要从s1中获得范围? – TheLostMind

回答

1

您想使用的indexOf:

int location = strValue1.indexOf(strValue2); 

将返回开始的位置,或-1,如果它没有发现任何东西。 范围将由(位置,strValue2.length)给出

+0

非常感谢@ergonaut – Arsench