换行 [英] string in new line
本文介绍了换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含100个或更多字符的字符串.
前40个字符应显示在第一行,后40个字符应显示在第二行,依此类推...
我想在带有相同标签的新行标签中显示它.
I have a string with 100 or more characters.
The first 40 characters should be displayed in first line, the next 40 characters should be displayed in second line and so on...
I want to display it in a label with new line in the same label.
推荐答案
检查此内容:
Check this:
Declare a Global Variable
string ModifiedString = "";
Paste the below in Your Page_Load() Event, and Run the Application.
string OrginalValue = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
do
{
ModifiedString = ModifiedString + OrginalValue.Substring(0, 40) + "<br/>";
OrginalValue = OrginalValue.Remove(0, 40);
} while (OrginalValue.Length > 40);
ModifiedString = ModifiedString + OrginalValue;
label1.Text = ModifiedString;
我正在为您提供带有硬编码值的代码.它将为您提供一个解决方法.
您只需要使其通用即可最适合您.
I am giving you the code with hard-coded values. It will give you an idea how to go about it.
You just need to make it generic to work best for you.
string longString = "This is longish test string ...."; //The length should be more than 80 characters for this ex to work.
Label1.Text = longString.Substring(0, 40) + "<br />" + longString.Substring(40, 40); //make it more generic so that it doesn't throw out of range exception
希望这对您有帮助!
Hope this helps!
您可以固定标签的宽度,但不能解决您的问题.您跨度固定宽度.它会起作用.
因为如果明智地削减角色,就可以得到
你
r名称
像这样.
You can fix the width of the label but it will not solve you problem. You take a span fix the width. it will work.
Because if you cut character wise then you can get
you
r name
like this.
这篇关于换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文