如何在c#.net中从文本框中分割日期时间 [英] How to split datetime from textbox in c#.net

查看:85
本文介绍了如何在c#.net中从文本框中分割日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,

我有一个文本框(textbox1.text =03/06/2013-c003--04 / 06/2013-c001-05-05 / 2013- c022-00od95croxfv3wwwy6g4mexa--),上面的textbox1.text是我的输入,我在多行文本框中的输出应该是这样的。



Textbox2.text = 03/06 / 2013-c003--

04/06/2013-c001--

05/06 / 2013-c022-00od95croxfv3wwwy6g4mexa--

that输入应该在日期因子的帮助下分开,并且应该在特定日期分别显示在多行文本框中

Dear Friends ,
I am having a textbox with ( textbox1.text = "03/06/2013-c003--04/06/2013-c001--05/06/2013-c022-00od95croxfv3wwwy6g4mexa--" ) , And above textbox1.text is my input and my output in multiline textbox should look like .

Textbox2.text = 03/06/2013-c003--
04/06/2013-c001--
05/06/2013-c022-00od95croxfv3wwwy6g4mexa--
that is input should be separated with the help of date factor and should be displayed in multiline textbox separately for the particular date

推荐答案

string s = "03/06/2013-c003--04/06/2013-c001--05/06/2013-c022-00od95croxfv3wwwy6g4mexa--";
            string[] arr=s.Split(new string[] {"--"},StringSplitOptions.None);
            for (int i = 0; i < arr.Length; i++)
            {
                textBox1.Text += arr[i]+Environment.NewLine;
            }


你可以用' - '这个字符分割你的字符串。不需要Date。请尝试以下代码



You can split your string by '--' this characters.No need of Date. Try this below code

string textbox2 = "";
           string textbox1 = "03/06/2013-c003--04/06/2013-c001--05/06/2013-c022-00od95croxfv3wwwy6g4mexa--";
           string[] newtxt = Regex.Split(textbox1, @"--");
           foreach (var s in newtxt)
           {
                textbox2 =textbox2 + s + "--" + Environment.NewLine;
           }

           string finalMultilineText = textbox2.Substring(0, textbox2.Length - 4);





将此finalMultilineText绑定到多行文本框。希望这有助于



bind this finalMultilineText to your Multiline textbox. Hope this helps


这篇关于如何在c#.net中从文本框中分割日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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