如何在ASP.NET/C#中动态添加数字上标?
我想在如何在ASP.NET/C#中动态添加数字上标?,c#,asp.net,html,C#,Asp.net,Html,我想在C中的数字中添加SuperScript 例如: 1st, 2nd ...... 我想在ASP.NET/C# 请建议最好的解决方案。您可以使用标签: 1<sup>st</sup> 2<sup>nd</sup>, ... 1st-2nd。。。 将呈现为:1st 2nd,我不太确定您到底想要什么 不过你可以这样做 假设您有一个ASP.NET标签 <asp:Label ID="sample" runat="server" Text=""&
C
中的数字中添加SuperScript
例如:
1st, 2nd ......
我想在ASP.NET/C#
请建议最好的解决方案。您可以使用
标签:
1<sup>st</sup> 2<sup>nd</sup>, ...
1st-2nd。。。
将呈现为:1st 2nd,我不太确定您到底想要什么 不过你可以这样做 假设您有一个ASP.NET标签
<asp:Label ID="sample" runat="server" Text=""></asp:Label>
然后在后面的代码中,您可以执行类似的操作
sample.Text=string.Format("1<sup>st</sup>");
sample.Text=string.Format(“第一”);
这将输出为第一个,使用
标记是标记这些值的正确方法
我想在asp.net c中动态执行此操作#
如果您对区域设置有一定的了解,您可以自动将
标记添加到文本中
匹配
匹配值的输出
1st
第二
第十
第二十
第一千
第三
第十九
@Abhishek到目前为止您尝试了什么?发布一些代码。OP要求一种动态执行此操作的方法。这意味着什么?在代码背后执行此操作?他甚至明确地说,“我想在asp.net c#中动态地做这个。”我想他可能想要一种方法来更改文本中的所有数字,以便它们显示这个,尽管我不确定,这个问题不是很清楚。string.Format
在您的第二个代码示例中有什么意义?+1。回答得很好。我只希望它对作者有意义。谢谢。我正在做一个函数示例。
// this should go in a helper class
// Obviously this depends on locale. The regex can be altered to accept numbers
// with as many digits as desired. I think "th" is always an appropriate suffix
// in English (not sure).
private static readonly Regex _regex = new Regex( @"^(\d{1,8})(st|nd|rd|th)$", RegexOptions.Compiled );
public static string AddSuper( string value ) {
return _regex.Replace( value, "$1<sup>$2</sup>" );
}
// in code-behind
this.litMyText.Text = AddSuper( "1st" );
// a few test cases (also demonstrates processing multiple items)
// should match
var testValues = new[] { "1st", "2nd", "10th", "20th", "1000th", "3rd", "19th" };
foreach( string val in testValues ) {
Response.Write( AddSuper( val ) );
}
// should not match
testValues = new[] { "test", "nd", "fourth", "25", "hello world th", "15,things", "1 1 1thousand" };
foreach( string val in testValues ) {
Response.Write( AddSuper( val ) );
}
1<sup>st</sup>
2<sup>nd</sup>
10<sup>th</sup>
20<sup>th</sup>
1000<sup>th</sup>
3<sup>rd</sup>
19<sup>th</sup>