将文字剪成碎片 [英] Cut a text into pieces
问题描述
如何将标签字段中的文字剪成碎片?
示例;
field1.text = 02:15:01; //时间估算HH:MM:SS
CMB_HH.SelectedValue = field1.text(02:##:##)// 02
CMB_MM.SelectedValue = field1.text(##:15:##)// 15
CMB_SS.SelectedValue = field1.text(##:##:01)// 01
我尝试了什么:
https://msdn.microsoft。 com $ / $
https://msdn.microsoft.com
https://msdn.microsoft.com
< blockquote>几种方式,但最简单的是:
string input = 02:15:01;
string [] parts = input.Split(' :跨度>);
if (parts.Length > = 3 )
{
CMB_HH.SelectedValue = parts [ 0 ];
CMB_MM.SelectedValue = parts [ 1 ];
CMB_SS.SelectedValue = parts [ 2 ];
}
另一种方法是使用: String.Substring方法(Int32,Int32)(系统) [ ^ ]
如果(s.Length > = 7 )
{
string p1 = s.Substring( 0 , 2 );
string p2 = s.Substring( 3 , 2 跨度>);
string p3 = s.Substring( 6 , 2 跨度>);
Console.WriteLine( {0}:{1}:{2}, p1,p2,p3);
}
// 产生:
// 17:02:05
How can i cut a text in a label field into pieces?
Example;
field1.text = 02:15:01; //time impute HH:MM:SS
CMB_HH.SelectedValue = field1.text(02:##:##) // 02
CMB_MM.SelectedValue = field1.text(##:15:##) // 15
CMB_SS.SelectedValue = field1.text(##:##:01) // 01
What I have tried:
https://msdn.microsoft.com
https://msdn.microsoft.com
https://msdn.microsoft.com
Couple of ways, but the simplest is:
string input = "02:15:01"; string[] parts = input.Split(':'); if (parts.Length >=3) { CMB_HH.SelectedValue = parts[0]; CMB_MM.SelectedValue = parts[1]; CMB_SS.SelectedValue = parts[2]; }
Another way is to use: String.Substring Method (Int32, Int32) (System)[^]
if (s.Length >= 7) { string p1 = s.Substring(0,2); string p2 = s.Substring(3,2); string p3 = s.Substring(6,2); Console.WriteLine("{0}:{1}:{2}", p1, p2, p3); } //produces: //17:02:05
这篇关于将文字剪成碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!