修改外部文本文件 [英] Modify external text file
问题描述
你好,当我使用我的文本文件时,我有桌面应用程序,我随机选择一些单词。每个单词都在单行上。但我想编辑可能性,用户可以加载自己的单词。但是当我加载它时,我需要像我一样修改他的文件。用户在文件中写入例如:word; word2; word3或word word2 word3,他在由分号或空格分隔的同一行上有单词,我需要通过输入分隔单词在sigle行。我曾经尝试过替换;通过\\\\ n或类似的东西。
Hallo, I have desktop application when I use my text file where i randomly pick some words. Each word is on single line. But I want to edit possibility, that user can load his own words. But when i load it, I need to modify his file same like me. User has write in file for example: "word;word2;word3 or word word2 word3", he has words on same line separated by semicolon or space and I need to split word by enter to be on sigle line. I had tried something like replace ";" by "\r\n" or something like this.
推荐答案
1。使用 String.Split 拆分输入字符串[ ^ ]
2.打开你的文件追加: https://msdn.microsoft.com/en-us/library/system.io.file.appendtext%28v=vs.110%29.aspx [ ^ ]
3.使用 WriteLine [ ^ ]在循环中添加新单词...
4.关闭文件...
1. Split the input string using String.Split[^]
2. Open you file for append: https://msdn.microsoft.com/en-us/library/system.io.file.appendtext%28v=vs.110%29.aspx[^]
3. Use WriteLine[^] in a loop to add new words...
4. Close the file...
这篇关于修改外部文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!