首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SSRS-2008中,在字符串的两个字之后启动新行。

在SSRS-2008中,在字符串的两个字之后启动新行。
EN

Stack Overflow用户
提问于 2018-03-07 13:57:59
回答 2查看 205关注 0票数 0

我有一个来自db的字符串,单词由一个空格分隔。单词的数量可以从最少一个到最多六个,所以我本质上想要的是在第二个单词之后立即开始一个新行。例如,字符串“自然金融服务”需要在报告中显示为:预期结果。如果只有一个单词,那么就不应该有任何断行,我尝试过这个Replace(Fields!CustodianNameTxt.Value," ",Vbcrlf),但是这会导致字符串中的每个单词出现在一个单独的行中,比如:结果与我的当前表达式--这不是预期的,请有人建议是否有任何解决方案来实现这一点?提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-08 11:51:44

选择报表属性->代码

添加此函数(在VB中可能有更好的方法来实现相同的功能,这只是一个例子):

代码语言:javascript
复制
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

然后,遗嘱中的表达式就是:

代码语言:javascript
复制
Code.splitline(Fields!CustodianNameTxt.Value)
票数 0
EN

Stack Overflow用户

发布于 2018-03-07 16:48:25

可以这样做的一种方法是将字符串拆分成一个单词数组,然后使用six函数使用添加的CRLF重新构建字符串,在这个示例中,选择在isnothing内,以满足少于6个单词的行的需要:

代码语言:javascript
复制
=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," ")),"") 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49153700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档