历史评论归档

使用问题 · 277 次浏览
197906+abcd张三 创建于 2021-07-26 00:12
~历史讨论归档。~

回复内容
HopeLin 2021-07-26 10:25
#1

用这个C#代码加千分位简单点

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

// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context){
            var oldValue = context.GetVarValue("context");
            string tmp= oldValue as string;
            string[] strList=tmp.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            for (int i = 0; i < strList.Length; i++)
            {                         
                    string integerSub="";
                    string decimalSub="";
                    if(strList[i].IndexOf(".")>0)
                    {
                        integerSub=strList[i].Substring(0,strList[i].IndexOf(".")); 
                        decimalSub=strList[i].Substring(strList[i].IndexOf("."),strList[i].Length-strList[i].IndexOf("."));                        
                    }
                    else
                    {
                       integerSub = strList[i];
                    }                                    
                    string result = "";                
                    Regex regex = new Regex(@"((?<!^|\D)\d{3})",RegexOptions.RightToLeft);
                    if(regex.IsMatch(integerSub))
                    {
                       result = regex.Replace(integerSub,",$1");
                    }
                    strList[i]=result+decimalSub;
           }
           context.SetVarValue("context", string.Join("\r\n",strList));
}
        
      
         

乘风破浪的嗷大喵 回复 HopeLin 2021-07-28 15:00 :

谢谢

回复主贴