本文介绍了格式字符串导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
在C#项目中,我遇到问题,请大家帮我!
我有一个要输入到文本框中的字符串,例如:
"
如果我必须在没有你的情况下过我的生活
日子将一无所有
夜晚似乎很长
和你在一起我会永远看到哦
我可能曾经恋爱过
但是从来没有感觉到如此强大的
"
没有报价.当我单击按钮时,我需要以下结果:

1.如果我不得不在没有你的情况下过我的生活
2.天将是空的
3.夜晚似乎很长
4.和你在一起我会永远看到哦
5.我可能曾经恋爱过
6.但是从来没有感觉到如此强大
在下面的字符串中,当我遇到输入字符时,它将执行子字符串,但只会剪切一次.
请帮助我!

Hello everybody!
In project C#, I have a problem, please everybody help me!
I have a string that i will enter to textbox, example:
"
If I had to live my life without you near me
The days would all be empty
The nights would seem so long
With you I see forever oh so clearly
I might have been in love before
But it never felt this strong
"
dont have quote. When i click button, i need a following results:

1. If I had to live my life without you near me
2. The days would all be empty
3. The nights would seem so long
4. With you I see forever oh so clearly
5. I might have been in love before
6. But it never felt this strong
in below string, when i meet enter character, it will do substring, but it only cut one time.
Please help me!

推荐答案


string a = @"If I had to live my life without you near me
                  The days would all be empty
                  The nights would seem so long
                  With you I see forever oh so clearly
                  I might have been in love before
                  But it never felt this strong";

string[] lines = a.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

StringBuilder s = new StringBuilder();

for (int i = 0; i < lines.Length; i++)
{
   s.AppendFormat("{0}. {1}{2}", i + 1, lines[i], Environment.NewLine);
}

string newString = s.ToString();




干杯




Cheers


这篇关于格式字符串导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 22:54