문자열이 있습니다.
string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
문자열에서 &&& 기호가 나올 때마다 줄 바꿈을 추가해야 합니다.
내 출력은 다음과 같아야 합니다.
fkdfdsfdflkdkfk@
dfsdfjk72388389@
kdkfkdfkkl@
jkdjkfjd@
jjjk@
그럼 그냥 이전 수정하십시오 정답:
Console.Write(strToProcess.Replace("@", "@" + Environment.NewLine));
뉴 라인 등 다른 새로운 텍스트 파일의 줄 수 있다고 주장한 챨 부여하느뇨 windows 에서. 다음과 같이 해 보십시오.
using System;
using System.IO;
static class Program
{
static void Main()
{
WriteToFile
(
@"C:\test.txt",
"fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@",
"@"
);
/*
output in test.txt in windows =
fkdfdsfdflkdkfk@
dfsdfjk72388389@
kdkfkdfkkl@
jkdjkfjd@
jjjk@
*/
}
public static void WriteToFile(string filename, string text, string newLineDelim)
{
bool equal = Environment.NewLine == "\r\n";
//Environment.NewLine == \r\n = True
Console.WriteLine("Environment.NewLine == \\r\\n = {0}", equal);
//replace newLineDelim with newLineDelim + a new line
//trim to get rid of any new lines chars at the end of the file
string filetext = text.Replace(newLineDelim, newLineDelim + Environment.NewLine).Trim();
using (StreamWriter sw = new StreamWriter(File.OpenWrite(filename)))
{
sw.Write(filetext);
}
}
}
간단한 문자열 바꾸기로 작업을 수행할 수 있습니다. 아래 예제 프로그램을 살펴보세요:
using System;
namespace NewLineThingy
{
class Program
{
static void Main(string[] args)
{
string str = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
str = str.Replace("@", "@" + Environment.NewLine);
Console.WriteLine(str);
Console.ReadKey();
}
}
}
답장 따라 다른 사람들, 이 같은 일이 뭐가 you& # 39, re 찾고 있습니다.
string file = @"C:\file.txt";
string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
string[] lines = strToProcess.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
using (StreamWriter writer = new StreamWriter(file))
{
foreach (string line in lines)
{
writer.WriteLine(line + "@");
}
}
string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
var result = strToProcess.Replace("@", "@ \r\n");
Console.WriteLine(result);
[] '뭔가 = 텍스트 문자열을 사용할 수도 있습니다. 분리-정합성 (& # 39, @& # 39;) '. 작은 따옴표, @" " 둘러싸기 위해 사용해야 합니다. 이를 '저장하였습니다 챨' 유형:. 이 문자를 저장할 경우 최대 @" 등 각 "; 개별 단어로 config. 어레이입니다. 그런 다음 각 출력입니다 for 루프 ('요소점 + 시스템.렌비론망.뉴선') 또는 쓸 사용하여 텍스트 파일로 '시스템드리오트피레스라이트일린스 ([파일 경로를 + 이름과 확장명은], [어레이입니다 이름])'. # 39 해당 위치에 있을 경우, t 타임코드가 doesn& 지정된 파일을 자동으로 생성됩니다.
protected void Button1_Click(object sender, EventArgs e)
{
string str = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
str = str.Replace("@", "@" + "<br/>");
Response.Write(str);
}
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";
strToProcess.Replace("@", Environment.NewLine);
Console.WriteLine(strToProcess);
}
}