我有一个来自db的字符串,单词由一个空格分隔。单词的数量可以从最少一个到最多六个,所以我本质上想要的是在第二个单词之后立即开始一个新行。例如,字符串“自然金融服务”需要在报告中显示为:预期结果。如果只有一个单词,那么就不应该有任何断行,我尝试过这个Replace(Fields!CustodianNameTxt.Value," ",Vbcrlf),但是这会导致字符串中的每个单词出现在一个单独的行中,比如:结果与我的当前表达式--这不是预期的,请有人建议是否有任何解决方案来实现这一点?提前谢谢。
发布于 2018-03-08 11:51:44
选择报表属性->代码
添加此函数(在VB中可能有更好的方法来实现相同的功能,这只是一个例子):
Public Function splitline(byval line as string) as string
dim words() as string=line.split(" ") ' separate the lines into array of words
dim pos as integer ' to calculate the position for the breaks
dim newlines as string = line ' string for the line with added breaks
if words.length > 2 then ' there are 3 or more words add break after second word
pos=len(words(0)) + len(words(1)) + 1 ' this will be the position of the first break
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
if words.length > 4 then ' there are 5 or more words add break after forth word
pos=len(words(0)) + len(words(1)) + len(words(2)) + len(words(3)) + 4 ' adding 4 because 2 spaces + cr + lf
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
return newlines
End Function然后,遗嘱中的表达式就是:
Code.splitline(Fields!CustodianNameTxt.Value)发布于 2018-03-07 16:48:25
可以这样做的一种方法是将字符串拆分成一个单词数组,然后使用six函数使用添加的CRLF重新构建字符串,在这个示例中,选择在isnothing内,以满足少于6个单词的行的需要:
=IIF(not isnothing(choose(1,split(Fields!CustodianNameTxt.Value," ")))," " + choose(1,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(2,split(Fields!CustodianNameTxt.Value," ")))," " + choose(2,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(3,split(Fields!CustodianNameTxt.Value," ")))," " + choose(3,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(4,split(Fields!CustodianNameTxt.Value," ")))," " + choose(4,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(5,split(Fields!CustodianNameTxt.Value," ")))," " + choose(5,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(6,split(Fields!CustodianNameTxt.Value," ")))," " + choose(6,split(Fields!CustodianNameTxt.Value," ")),"") https://stackoverflow.com/questions/49153700
复制相似问题