有没有“Unformat”函数?(10分)

  • 主题发起人 主题发起人 _zeus
  • 开始时间 开始时间
Z

_zeus

Unregistered / Unconfirmed
GUEST, unregistred user!
有没有一个函数能实现“Unformat”?例如:<br><br>
代码:
var<br>&nbsp; s1, s2, i, s3, s4, s5, s6: String;<br>begin<br>&nbsp; Unformat('There are 2 apples on the table', '%s %s %d %s %s %s %s',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[s1, s2, i, s3, s4, s5, s6]);<br>end;
<br><br>然后 s1 = 'There'、s2 = 'are'、i = 2、s3 = 'apples'、s4 = 'on'、s5 = 'the'、<br>s6 = 'table'。
 
什么意思?是指每个空格以后的内容,转成相应的格式么?<br>如果只是你上面两重类型,自己写个循环处理就可以了<br><br>
 
function Unformat(S:String):TStrings;<br>begin<br>&nbsp; Result:=TStringList.Create;<br>&nbsp; ExtractStrings([' '],[],PChar(s),Result);<br>end;<br><br>var<br>&nbsp; s:String;<br>&nbsp; l:TStrings;<br>&nbsp; i:Integer;<br>begin<br>&nbsp; s:='There are 2 apples on the table';<br>&nbsp; l:=UnFormat(s);<br>&nbsp; for i:=0 to l.Count -1 do<br>&nbsp; &nbsp; ShowMessage(l);<br>&nbsp; l.Free;<br>end;
 
后退
顶部