2014-10-09 4 views
0

나는 문자열이 있습니다. 일부 내용은 변경 될 수 있으며 일부 내용은 수정 될 수 있습니다.String in Java의 문장을

그것은 같은 것입니다 :

String mycontent = "here is the sentence 1 . here is the sentence 2 . hereisthesomesentence3.here is the sentence 4. " 

sentence 1 content : changeable , 
sentence 2 content : fixed  , 
sentence 3 content : changeable , 
sentence 4 content : changeable . 

내가

String sentence3 = "hereisthesomesentence3" 

주와 같은 문장 뭔가를 3 컨텐츠를 먹고 싶어 : 나는 문자열의 일부가 될 수 있기 때문에 얼마나 많은 문장 모른다 변경되었습니다. 10 또는 20 문장으로 끝날 수 있습니다. 내 캐릭터의

내용은 같은 것입니다 :

이 예제 코드 3
some paragraphs in here.// i do not know what is it writing . After this changeable contents 
fixed content :"url" // fixed content not change . But url can be change **i want to get url** 
some other paragraphs in here // here some other contents. 

:; 그래서

Some Other Paragraphs 
FIXED TEXT  

<span class="subcat2"><a href="myurl"> 
    <span style="display: inline-block; float: left; color: #ccc !important;"></span> Hello World!!!!!!!!!!!!!!!!!!!!!!!!!! 
</a></span> 

Some Other Paragraphs 
+0

내용이 "변경 가능"하기 때문에'System.out.println ("changeable")'을 사용하십시오 ... * flies away * : D – Joffrey

+0

그래서이 문자열의 구조가 정확히 어떻게 보입니까? –

+1

* 문장의 정의는 무엇입니까? 마침표가있을 때마다 새로운 문장이 시작된다는 뜻입니까? ** "스미스가 35.7 초 만에 샤워를했다"같은 문장이 있습니까? **? – Joffrey

답변

1

(내 URL을 얻으려면 우리는 여전히 변경 일부가, 일부는 고정) 모든 문장은 쉼표로 구분됩니다. 그럼 그냥 분할이 있습니다

이 같은
public class HelloWorld{ 

    public static void main(String []args){ 
    String myContent ="here is the sentence 1 . here is the sentence 2 . hereisthesomesentence3.here is the sentence 4. "; 

    String[] parts = myContent.split("\\."); 
    System.out.println("Amount of parts = " + parts.length); 
    System.out.println("Sentence 3 = " + parts[2].trim()); // trim() removes leading and trailing whitespaces 
    } 
} 
+3

이있을 수 있습니다. 점을 기준으로 분할해야한다고 생각합니다. – TheLostMind

+3

'.'으로 나눌 수 있습니다. 결과를 다듬습니다. –

+0

내 문장 하나 ** "M. Smith가 35.7 초 만에 샤워를했다."**? – Joffrey

1

뭔가 작동합니다

public static void main(String[] args) { 
    String mycontent = "here is the sentence 1 . here is the sentence 2 . hereisthesomesentence3.here is the sentence 4. "; 
    System.out.println(mycontent.split("\\.")[2].trim()); 
} 

output : 
hereisthesomesentence3 
+0

거기에 얼마나 많은 점이 있는지 모르겠다. – user3632921

+0

@ user3632921 - 그게 무슨 뜻이야?. 당신이하고 싶은 말의 예를 보여줄 수 있습니까? – TheLostMind

+0

문장 1에 10 문장이있을 수 있습니다. 변경 가능하기 때문에 문장 2를 사용해야합니다.거기에서 나는 무엇이 쓰여 있는지 알고 있고 나는 단지 문장 2 이후에 문장을 얻고 싶기 때문에. – user3632921

0

코드

String mycontent = 
    "here is the sentence 1 . here is the sentence 2 . here isthesomesentence3.here is the sentence 4. " 
String[] totalSentance = mycontent.split("\\."); 
System.out.println("Sentence No. 3 = " + totalSentance[2]); 
+1

이 이미 두 번 대답했습니다 ... 'trim() – Joffrey

0

무엇 getSentenceInstance and whitespace

Scanner input = new Scanner(new File("some/path/to/sampleinput.txt")); 

    ArrayList theSentences = new ArrayList<String>(); 
    String myText = String.valueOf(input); //the text is produced through a text box 
    BreakIterator boundary = BreakIterator.getSentenceInstance(); 
    boundary.setText(myText); 
    int start = boundary.first(); 
    for (int end = boundary.next(); end != BreakIterator.DONE; start = end, end = boundary.next()) 
    { 
     String temp = myText.substring(start,end); 
     theSentences.add(temp.trim()); 
    } 
에서 적응이 같은 약