2015-06-25 218 views
1

首先,我是PowerBuilder的noob,似乎无法找到如何在任何地方执行此操作。在PowerBuilder中循环遍历字符串

我已经给了重写应用程序的任务。我的老板希望新的应用程序尽可能地模仿旧的应用程序,这会导致我的问题。有一个日期字段允许用波形符号(01/01/15〜01/31/15)分隔日期输入,并使用它来获取SQL语句之间的开始日期和结束日期。

尽管如此,我正试图在PowerBuilder 12.6 classic中做同样的事情。我知道我可以通过使用两个日期选择器(开始日期和结束日期)完成同样的事情,但是我的老板希望这种转换对最终用户尽可能无缝。

我在我的表格上有一个sle_date_shipped,它现在采用mm/dd/yy的日期格式并将处理它,但是我想允许mm/dd/yy〜mm/dd/yy并解析出一个开始和结束日期。我的伪代码将是这个样子:

int i 
String s 
String start_date 
String end_date 

if this.textsize > 8 then 
    s = this.text(value of this position in the string) 
    start_date = s + s 
    if this.text = "~" then 
     s = s + 1 
     s = this.text(value of this position in the string) 
     end_date = s + s 
    end if 
    this.textsize + 1 
else 
    start_date = this.text 
end if 

我也知道我的伪代码可能需要一些工作,我只是想传达出点。

感谢

回答

2

不循环......

string ls_start, ls_end 
ls_start = left(this.text, pos(this.text, '~') - 1) 
ls_end = right(this.text, Len(this.text) - pos(this.text, '~')) 

- 保罗Horan-

+0

哇!谢谢。如果你知道你在做什么,PowerBuilder非常简单。这很好用!我准备将字符串转换为一个字符数组,循环通过它,哈哈。 – CuriousOne

+0

只要确保您'测试'日期以确保它们确实是日期。您可以使用IsDate方法。 –