将行连接成一个字符串 [英] Concatenate lines into one string

查看:30
本文介绍了将行连接成一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将文本从字符串拆分和编辑为某个公式.

I need to split and edit text from string to a certain formula.

文本字符串为:

1
2
3
4
5

1
2
3
4
5

1
2
3
4
5

1
2
3
4
5

1
2
3
4
5

 

我需要它:

1;2;3;4;5
<br>
1;2;3;4;5
<br>
1;2;3;4;5
<br>
1;2;3;4;5
<br>
1;2;3;4;5
<br>
1;2;3;4;5
<br>


在 1 个字符串中,我有 50 个我需要它作为该公式的行.
我尝试使用按新行拆分并为每个单词添加字符,然后按字符拆分,但对我没有帮助.


In 1 string i have like 50 of those I need it to be lines of that formula.
Ive tried to use split by new lines and adding chars to every word and then split by char but it doesnt helped me.

推荐答案

假设换行符是作为 CR/LF 序列给出的

Assuming that the line breaks are given as a CR/LF sequence

Dim result = input.Replace(vbCrLf, ";")

Dim result = input.Replace(Environment.NewLine, ";")

参见:https://dotnetfiddle.net/pB08ay

您更新后的更复杂的输入字符串可以这样处理

Your updated more complex input string can be processed like this

Dim result = input.Replace(Environment.NewLine, ";").
                   Replace(";;", Environment.NewLine & "<br>" & Environment.NewLine)

我们像以前一样开始.这会产生一个看起来像 1;2;3;4;5;;1;2;3;4;5;;1;2;3;4;5;;1;2;3;4; 的字符串.5;;1;2;3;4;5.然后我们用嵌入在两个换行符之间的
替换双分号.

We begin as before. This produces a string looking like 1;2;3;4;5;;1;2;3;4;5;;1;2;3;4;5;;1;2;3;4;5;;1;2;3;4;5. Then we replace the double semicolon by the <br> embedded between two line breaks.

这篇关于将行连接成一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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