Как получить весь текст из документа, связанного с строкой. Я пытаюсь разделить текст по точкам: string[] words = s.Split('.');
Я хочу взять этот текст из текстового документа. Но если мой текст документа содержит пустые строки между строками, например:Как связаться с целым текстом из файла в строку, избегая пустых строк beetwen строк
pat said, “i’ll keep this ring.”
she displayed the silver and jade wedding ring which, in another time track,
she and joe had picked out; this
much of the alternate world she had elected to retain. he wondered what - if any - legal basis she had kept in addition. none, he hoped; wisely, however, he said nothing. better not even to ask.
результат выглядит следующим образом:
1. pat said ill keep this ring
2. she displayed the silver and jade wedding ring which in another time track
3. she and joe had picked out this
4. much of the alternate world she had elected to retain
5. he wondered what if any legal basis she had kept in addition
6. none he hoped wisely however he said nothing
7. better not even to ask
но нужный правильный вывод должен быть таким:
1. pat said ill keep this ring
2. she displayed the silver and jade wedding ring which in another time track she and joe had picked out this much of the alternate world she had elected to retain
3. he wondered what if any legal basis she had kept in addition
4. none he hoped wisely however he said nothing
5. better not even to ask
Так для этого сначала мне нужно обработать содержимое текстового файла, чтобы получить весь текст в виде отдельной строки, например:
pat said, “i’ll keep this ring.” she displayed the silver and jade wedding ring which, in another time track, she and joe had picked out; this much of the alternate world she had elected to retain. he wondered what - if any - legal basis she had kept in addition. none, he hoped; wisely, however, he said nothing. better not even to ask.
Я не могу сделать это так же, как это было бы с содержанием списка, например: string concat = String.Join(" ", text.ToArray());
,
Я не уверен, как связаться текст в строку из текстового документа
Вы предполагаете, что файл будет использовать те же символы новой строки, что и машина. Это приведет к сбою в Windows с файлами, которые используют '\ n' –
Да, это зависит от конкретного файла. Но не стоит заменять «Environment.NewLine» новым символом строки, который используется в файле. – tomassino