C#從零開始_自學C#、Visual Studio實境秀 57 時間軸冒號轉半形ConsoleApp





using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace 時間軸冒號轉半形ConsoleApp
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            string x = Clipboard.GetText();
            if (x!=string.Empty)
            {
                int j = x.Length;
                for (int i = 0; i < j-2; i++)
                {
                    if (isNum( x.Substring(i,1)) & x.Substring(i+1,1)==":" & isNum(x.Substring(i+2,1)))
                    {
                        x = x.Substring(0, i+1) + ":" + x.Substring(i + 2);
                        //x.Substring(i + 1, 1).Replace(":", ":");
                    }
                }
                Clipboard.SetText(x);
                //StringInfo xStrInfo = new StringInfo(x);
                //int j = xStrInfo.LengthInTextElements;
                //for (int i = 0; i <j; i++)
                //{
                //    if (isNum(xStrInfo.SubstringByTextElements(i, 1)))
                //    {
                //        if (xStrInfo.SubstringByTextElements(i+1, 1)==":" & isNum(xStrInfo.SubstringByTextElements(i+2, 1)))
                //        {
                //            xStrInfo..re = ":";
                //        }
                //    }
                //}

                //TextElementEnumerator tEStrInfo= StringInfo.GetTextElementEnumerator(x);
                //while (tEStrInfo.MoveNext())
                //{
                //    if (tEStrInfo.GetTextElement()==":")
                //    {
                //       tEStrInfo(tEStrInfo.ElementIndex)
                //    }
                //}
            }
        }

        static bool isNum(string str)
        {
            Regex rg = new Regex("[0-9]");
            return rg.IsMatch(str);
        }
    }
}

留言

熱門文章