我遇到一个麻烦问题,请高手指点!很急!!!!!!!!!!!!!!!!!!!!

liyx326 2004-04-08 11:12:23
开发工具pb8.03,数据库oracle8.
数据库的字段里面存着最大长度为100个汉字的字符。我现在要把它取出来打印在数据窗口上面,数据窗口的每一行最多只能容纳15个汉字,我用midw()函数加循环分别截取每行15个汉字。但是打印出来后效果是这样的:如果这一行全部是汉字则没有什么问题,15个汉字刚好满一行。但是如果这一行中有数字,他的后面就会有空格。如下所示:
“中华人民共和国万岁,世界人民大”(正常)
“中华人民共和国10000岁,世 ”(异常)
我现在想把异常的内容均匀分布在行中,而不是在后面有那么多空格。现在的规律是每行中有几个数字,后面肯定会有几个空格。pb8把一个数字也当成一个汉字的宽度来计算,但是在打印出来的时候效果很不好。
各位有什么好办法,分不够可以再加!!!!!!!!!!!!!
...全文
76 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangchi0532 2004-04-09
  • 打赏
  • 举报
回复
希望对你有启发!好运

$PBExportHeader$f_wordwrap_2.srf
$PBExportComments$实现正文的自动折行功能,且防止汉字被一切为二(返回处理后的字符)
global type f_wordwrap_2 from function_object
end type

forward prototypes
global function string f_wordwrap_2 (string as_text, integer ai_charincol)
end prototypes

global function string f_wordwrap_2 (string as_text, integer ai_charincol);//函数名:f_wordwrap
//参数1:as_text 要被处理的正文
//参数2:ai_charincol 一行放多少个字符(不包括回车)
//返回:as_tex 处理过的行

int i,li_len,j,k,l,li_totalrow
char lch_char,lch_next
string ls_wrappedtext,ls_next,ls_prev,ls_string

li_len = len(as_text)
j=0 //记ASCII大于127的字符个数
k=0 //记每一行的字符数
l =1 //每一行起始字符在正文中的位置
li_totalrow = 0
ls_wrappedtext = ""

for i=1 to li_len
lch_char = mid(as_text,i,1)
if asc(lch_char) > 127 then
j++
k++
else
if lch_char = '~r' then
li_totalrow++
k++
ls_wrappedtext += mid(as_text,l,k)
j = 0
l += k
k =0
elseif lch_char = '~n' then //新行
k++
ls_wrappedtext += mid(as_text,l,k)
l +=k
k --
else
k++
end if
end if

if k >= ai_charincol then//如一行已超过最大长度,则自动折行
lch_next = mid(as_text,i+1,1)
ls_next = mid(as_text,i+1,2)
ls_prev = mid(as_text,i,2)

if lch_next = '~r' or lch_next = '~n' then
continue
elseif lch_next = '.' or lch_next =',' or lch_next ='?' or lch_next ='!' &
or lch_next =')' or lch_next =']' or lch_next ='}' or lch_next =';' &
or lch_next =':' or lch_next ='~'' or lch_next ='~"' then

if i <> li_len -1 then
continue
else
exit
end if

elseif ls_prev = ',' or ls_prev ='。' or ls_prev = '?' &
or ls_prev = '!' or ls_prev = '”' or ls_prev ='’' or &
ls_prev =')' or ls_prev = ';' or ls_prev = ':' or ls_prev = '、' then

if i <> li_len -1 then
continue
else
exit
end if
elseif ls_next = ',' or ls_next ='。' or ls_next = '?' &
or ls_next = '!' or ls_next = '”' or ls_next ='’' or &
ls_next =')' or ls_next = ';' or ls_next = ':' or ls_next = '、' then

if i <> li_len -2 then
j++
i++
k++
continue
else
exit
end if
else

if mod(j,2) = 0 then
ls_wrappedtext = ls_wrappedtext + mid(as_text,l,k) + '~r~n'
else
ls_string = mid(as_text,l,k -1)
ls_wrappedtext = ls_wrappedtext + mid(as_text,l,k -1) + '~r~n'
i --
k --
end if

j = 0
l += k
k = 0
li_totalrow ++
end if
end if
next

ls_wrappedtext = ls_wrappedtext + mid(as_text,l)
as_text = ls_wrappedtext
li_totalrow ++
return ls_wrappedtext

end function
xiaoluoxy 2004-04-09
  • 打赏
  • 举报
回复
汉字:双字节
数字或字母:单字节

len(单个汉字) = 2
len(单个数字或字母) = 1

len(15个汉字) = 15*2 = 30
30/len(单个数字或字母) = 可以显示30个数字

用midw()函数加循环分别截取每行,遇汉字计2遇数字或字母计1直到满30为止
xyzliuin 2004-04-09
  • 打赏
  • 举报
回复
对了,也可能是pb的问题,打补丁试试
我最佩服pb这方面了!!!
lzheng2001 2004-04-09
  • 打赏
  • 举报
回复
请注意汉字是占2个字节的而数字是占1个字节的,请检查你的程序,有没有考虑这个问题.
feixianzhi 2004-04-09
  • 打赏
  • 举报
回复
呵呵,打8.04补丁,或者升级到9.01
xyzliuin 2004-04-09
  • 打赏
  • 举报
回复
“pb8把一个数字也当成一个汉字的宽度来计算”,是吗? 我还真没注意!

midw()是什么函数?你自己写的?是截取宽字符的吧,为什么不用mid()

1,108

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧