C#中的格式段落 [英] Format Paragraph in C#

查看:66
本文介绍了C#中的格式段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我:

我有段落,复制到文本框:



----------- -------------------------------------------------- ---

1.< title>元素50m 45s

在浏览器工具栏中定义标题15m 20s

为页面添加到收藏夹时提供标题15m 10s

在搜索引擎结果中显示页面的标题20m 15s

2.可以通过以下方式将CSS添加到HTML中21m 40s

内联 - 使用style属性HTML元素5m 10s

内部 - 使用< style> < head>中的元素部分10m 3s

外部 - 使用外部CSS文件6m 27s

---------------------- ------------------------------------------



我想用C#格式化这个段落,它会删除每个标题行末尾的所有时间。然后它插入每个标签html,当我点击按钮时,它将在代码html中显示如下:

---------------------- ------------------------------------------

< ul>

< li> 0。 & lt; title& gt;元素

< ul>

< li>在浏览器工具栏中定义标题< / li>

< li>提供将页面添加到收藏夹时的页面标题< / li>

< li>在搜索引擎结果中显示该页面的标题< / li>

< / ul>< / li>

< li> 1。 CSS可以通过以下方式添加到HTML

< ul>

< li>内联 - 使用HTML元素中的style属性< / li>

< li>内部 - 使用& lt; style& gt; & lt; head& gt;中的元素部分< / li>

< li>外部 - 使用外部CSS文件< / li>

< / ul>< / li>

< / ul>

--------------------------------- -------------------------------



非常感谢你很多。

解决方案

你几乎就在那里。以下代码接受此输入



 1。 <   title  > 元素50m 45s 
在浏览器工具栏中定义标题15m 20s
为页面添加到收藏夹时提供标题15m 10s
在搜索引擎结果中显示页面标题20m 15s
2. CSS可以通过以下方式添加到HTML中21m 40s
内联 - 使用HTML元素中的style属性5m 10s
内部 - 使用 < style > 元素< head > 部分10m 3s
外部 - 使用外部CSS文件6m 27s





并提供此输出,我收集的是你想要的输出。



 <   ul  >  
< < span class =code-leadattribute> li > 1。 < title > 元素50m 45s < / li >
< li > 在浏览器工具栏中定义标题15m 20s < / li >
< li > 在将页面添加到收藏夹时提供页面标题15m 10s < / li >
< li > 显示标题对于搜索引擎结果中的页面20m 15s < / li >
< li > 2。可以通过以下方式将CSS添加到HTML中21m 40s < / li >
< li > 内联 - 使用HTML元素中的style属性5m 10s < / li >
< li > 内部 - 使用< < style > 元素> head
> 部分10m 3s < / li & gt;
< li > 外部 - 使用外部CSS文件6m 27s < / li >
< / ul >





我几乎使用你评论中的内容以上。



  var  inputValue = 
@ 1。 < title>元素50m 45s
在浏览器工具栏中定义标题15m 20s
为页面添加到收藏夹时提供标题15m 10s
在搜索引擎结果中显示页面标题20m 15s
2. CSS可以通过以下方式添加到HTML中21m 40s
内联 - 使用HTML元素中的style属性5m 10s
内部 - 使用< style> < head>中的元素部分10m 3s
外部 - 使用外部CSS文件6m 27s
;

var lines = inputValue.Split ( new [] {Environment.NewLine},StringSplitOptions.None);
var buildstr = new StringBuilder();

buildstr.Append( < ul> + Environment.NewLine);
foreach var line in lines)
{
buildstr.AppendFormat( < li> {0} {1}< / li>,line.Trim(),Environment.NewLine);
}
buildstr.Append( < / ul> + Environment.NewLine);

Console.WriteLine(buildstr.ToString());









如果你想删除时间这个方法使用Linq和Regex删除时间。



  var  inputValue = 
@ 1。 < title>元素50m 45s
在浏览器工具栏中定义标题15m 20s
为页面添加到收藏夹时提供标题15m 10s
显示搜索页面的标题-engine结果20m 15s
2. CSS可以通过以下方式添加到HTML中21m 40s
内联 - 使用HTML元素中的style属性5m 10s
内部 - 使用< style> < head>部分中的元素10m 3s
外部 - 使用外部CSS文件6 m 27s
;

var lines = inputValue.Split( new [] {Environment.NewLine },StringSplitOptions.None);
var buildstr = new StringBuilder();

buildstr.Append( < ul> + Environment.NewLine );
foreach 字符串换行符 lines.Select(line = > Regex.Replace(line, [0-9] + s ))。选择(换行符= > Regex.Replace(换行符, [0-9] + m )))
{
buildstr.AppendFormat( < li> {0}< / li> {1} ,newline.Trim(),Environment.NewLine);
}
buildstr.Append( < / ul> + Environment 。新队);

Console.WriteLine(buildstr.ToString());





哪个给出了这个输出



 <   ul  >  
< li > 1。 < title > 元素< span class =code-keyword>< / li >
< li > 定义浏览器工具栏中的标题< / li >
< li > 在将页面添加到收藏夹< / li >
< li < span class =code-keyword>> 在search-e中显示页面的标题ngine结果< / li >
< li > 2。 CSS可以通过以下方式添加到HTML < / li >
< li > 内联 - 使用HTML元素中的style属性< / li >
< li > 内部 - 使用< style > 元素在< head > 部分< / li >
< li > 外部 - 使用外部CSS文件< / li >
< / ul >


Please help me:
I have paragraph, copy to textbox:

----------------------------------------------------------------
1. The <title> element 50m 45s
defines a title in the browser toolbar 15m 20s
provides a title for the page when it is added to favorites 15m 10s
displays a title for the page in search-engine results 20m 15s
2. CSS can be added to HTML in the following ways 21m 40s
Inline - using the style attribute in HTML elements 5m 10s
Internal - using the <style> element in the <head> section 10m 3s
External - using an external CSS file 6m 27s
----------------------------------------------------------------

I want format this paragraph with C#, it will delete all time at end of every title row. Then it insert every tag html, when i click button, it will show below in code html:
----------------------------------------------------------------
<ul>
<li>0. The &lt;title&gt; element
<ul>
<li>defines a title in the browser toolbar </li>
<li>provides a title for the page when it is added to favorites </li>
<li>displays a title for the page in search-engine results </li>
</ul></li>
<li>1. CSS can be added to HTML in the following ways
<ul>
<li>Inline - using the style attribute in HTML elements</li>
<li>Internal - using the &lt;style&gt; element in the &lt;head&gt; section</li>
<li>External - using an external CSS file</li>
</ul></li>
</ul>
----------------------------------------------------------------

Thank you very much.

解决方案

You were pretty much there. The following code takes this input

1. The <title> element 50m 45s
defines a title in the browser toolbar 15m 20s
provides a title for the page when it is added to favorites 15m 10s
displays a title for the page in search-engine results 20m 15s
2. CSS can be added to HTML in the following ways 21m 40s
Inline - using the style attribute in HTML elements 5m 10s
Internal - using the <style> element in the <head> section 10m 3s
External - using an external CSS file 6m 27s



and provides this output which from what i gather is your desired output.

<ul>
<li>1. The <title> element 50m 45s</li>
<li>defines a title in the browser toolbar 15m 20s</li>
<li>provides a title for the page when it is added to favorites 15m 10s</li>
<li>displays a title for the page in search-engine results 20m 15s</li>
<li>2. CSS can be added to HTML in the following ways 21m 40s</li>
<li>Inline - using the style attribute in HTML elements 5m 10s</li>
<li>Internal - using the <style> element in the <head> section 10m 3s</li>
<li>External - using an external CSS file 6m 27s</li>
</ul>



I am pretty much using what you had in your comment above.

var inputValue =
                @"1. The <title> element 50m 45s
                    defines a title in the browser toolbar 15m 20s
                    provides a title for the page when it is added to favorites 15m 10s
                    displays a title for the page in search-engine results 20m 15s
                    2. CSS can be added to HTML in the following ways 21m 40s
                    Inline - using the style attribute in HTML elements 5m 10s
                    Internal - using the <style> element in the <head> section 10m 3s
                    External - using an external CSS file 6m 27s";

            var lines = inputValue.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var buildstr = new StringBuilder();

            buildstr.Append("<ul>" + Environment.NewLine);
            foreach (var line in lines)
            {
                buildstr.AppendFormat("<li>{0}{1}</li>", line.Trim(), Environment.NewLine);
            }
            buildstr.Append("</ul>" + Environment.NewLine);

            Console.WriteLine(buildstr.ToString());





If you desire to remove the times this method using Linq and Regex to remove the times.

var inputValue =
                @"1. The <title> element 50m 45s
                    defines a title in the browser toolbar 15m 20s
                    provides a title for the page when it is added to favorites 15m 10s
                    displays a title for the page in search-engine results 20m 15s
                    2. CSS can be added to HTML in the following ways 21m 40s
                    Inline - using the style attribute in HTML elements 5m 10s
                    Internal - using the <style> element in the <head> section 10m 3s
                    External - using an external CSS file 6m 27s";

            var lines = inputValue.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var buildstr = new StringBuilder();

            buildstr.Append("<ul>" + Environment.NewLine);
            foreach (string newline in lines.Select(line => Regex.Replace(line, "[0-9]+s", "")).Select(newline => Regex.Replace(newline, "[0-9]+m", "")))
            {
                buildstr.AppendFormat("<li>{0}</li>{1}", newline.Trim(), Environment.NewLine);
            }
            buildstr.Append("</ul>" + Environment.NewLine);

            Console.WriteLine(buildstr.ToString());



Which gives this output

<ul>
<li>1. The <title> element</li>
<li>defines a title in the browser toolbar</li>
<li>provides a title for the page when it is added to favorites</li>
<li>displays a title for the page in search-engine results</li>
<li>2. CSS can be added to HTML in the following ways</li>
<li>Inline - using the style attribute in HTML elements</li>
<li>Internal - using the <style> element in the <head> section</li>
<li>External - using an external CSS file</li>
</ul>


这篇关于C#中的格式段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆