从Java中的字符串获取句子

从Java中的字符串获取句子,java,string,search,Java,String,Search,我有一根绳子。它的某些内容可以更改,而某些内容是固定的 就像: 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 : changea

我有一根绳子。它的某些内容可以更改,而某些内容是固定的

就像:

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"
注意:我不知道有多少个句子,因为字符串的一部分可以更改。最后我可能会说10到20句话

我的字符串的内容如下所示:

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. 
示例代码3:(我想获取我的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
   }
 }

类似这样的方法会奏效:

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
代码

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]);

像这样的东西,改编自

Scanner input=new Scanner(新文件(“some/path/to/sampleinput.txt”);
ArrayList theContents=新建ArrayList();
String myText=String.valueOf(输入)//文本通过文本框生成
BreakIterator边界=BreakIterator.getSentenceInstance();
边界.setText(myText);
int start=boundary.first();
for(int end=boundary.next();end!=BreakIterator.DONE;start=end,end=boundary.next())
{
String temp=myText.substring(开始、结束);
内容添加(临时修剪());
}

我想你需要根据一个点进行分割。你可以按“.”分割结果。那我的第一句话“史密斯先生在35.7秒内洗了个澡”怎么样?谢谢,我得检查一下眼睛D:)。点比拆分正则表达式更难,点是一个特殊的正则表达式字符,所以要小心。考虑到字符串下的值,它可能是comas,而不是dots。这个问题并不精确,但若它是点,那个么你们可以通过
字符串来拆分它;只需使用
System.out.println(“可更改的”)
,因为内容是“可更改的”。。。飞走:Dso,这个字符串的结构看起来有多精确?你们对这个句子的定义是什么?你的意思是每次有句号,一个新句子就开始了吗?有没有像“M.Smith在35.7秒内洗澡”这样的句子?这个字符串,我不知道它是什么内容。我只知道有些东西是固定不变的。我想在固定的单词之后获得内容。不知道里面有多少圆点there@user3632921-你这是什么意思?。你能举一个你想说什么的例子吗?句子1中可能有10个句子。因为它是可变的。所以我应该使用句子2。因为在那里我知道它写的是什么,我只想在第2句后面加一个句子。@user3632921-向我们展示你正在谈论的输入。我添加了一些新内容。我希望你这次能理解
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]);
    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());
    }