以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于替换语句的问题 ----求助!!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=33668)

--  作者:sandygood
--  发布时间:2013/5/22 15:29:00
--  关于替换语句的问题 ----求助!!

    语句  “45[上月余额]+65[本月余额]”

 

Dim s As String =e.DataRow("计算公式")
s = s.Replace("[*]","")

 

 

请问计算时如何将“[ 。。 ]”全部替换为空,应为它是备注。



--  作者:Bin
--  发布时间:2013/5/22 15:55:00
--  
使用正则表达式
MessageBox.Show(System.Text.RegularExpressions.Regex.Replace("45[上月余额]+65[本月余额]", "\\[[\\u4e00-\\u9fa5]+\\]", ""))
--  作者:sandygood
--  发布时间:2013/5/22 16:16:00
--  

我是在表事件 datacolchanged里面的,

 

If e.DataCol.Name = "计算公式" Then
    If e.DataRow.IsNull("计算公式") Then
        e.DataRow("数量") = Nothing
    Else
Dim s As String =e.DataRow("计算公式")
s = s.replace("[","")
        e.DataRow("数量") = Eval(s,e.DataRow)
    End If
End If

 

按楼上的做法好像不行,求解!


--  作者:Bin
--  发布时间:2013/5/22 16:23:00
--  
呵呵.不可能不行的.  你怎么用的?
--  作者:Bin
--  发布时间:2013/5/22 16:26:00
--  
实在不行你上例子吧.套用都不会 你该提升一下自己了.图片点击可在新窗口打开查看
--  作者:sandygood
--  发布时间:2013/5/22 16:43:00
--  

 

在表事件 datacolchanged里面的,

 

If e.DataCol.Name = "计算公式" Then
    If e.DataRow.IsNull("计算公式") Then
        e.DataRow("数量") = Nothing
    Else
Dim s1 As String =e.DataRow("计算公式")
s1 = System.Text.RegularExpressions.Regex.Replace(s1, "\\[[\\u4e00-\\u9fa5]+\\]", "")  
     e.DataRow("数量") = Eval(s1,e.DataRow)
    End If
End If

 

 

此代码在表事件中不能执行

[此贴子已经被作者于2013-5-22 17:18:57编辑过]

--  作者:狐狸爸爸
--  发布时间:2013/5/22 17:57:00
--  
设置完之后,对于已经输入的数据,要重置一下列