파워빌더/공통함수
파워빌더.공통함수 - 문자열을 배열로 만들기
농부지기
2017. 1. 26. 23:51
[ 파워빌더.공통함수 - 문자열을 배열로 만들기 ]
☞ 첫 번째 방법 |
|
구분자 있는 스트링 변수를 나누어서 스트링 배열에 담아주는 함수 입니다.
예를 들어...
sOrg = "aaa;bbb;ccc"
sDiv = ';' //구분자
= > sVal[1] => 'aaa'
= > sVal[2] => 'bbb'
= > sVal[3] => 'ccc'
//f_div_String( sOrg, sDiv, sVal[] )
Int i Long lPos, lStart, lLen
i = 1 lStart = 1 lLen = Len(sOrg)
lPos = Pos(sOrg, sDiv, lStart) if lPos < 1 then //구분자 없을 때 sVal[1] = sOrg return elseif lpos = 1 then //구분자 첫번째에 만날때 lStart = lStart + Len(sDiv) lPos = Pos(sOrg, sDiv, lStart) end if do while lPos > 0 sVal[i] = Mid(sOrg, lStart, lPos - lStart) if lLen = (lPos + Len(sDiv) - 1) then return
i ++ lStart = lPos + Len(sDiv) lPos = Pos(sOrg, sDiv, lStart) loop
sVal[i] = mid(sOrg, lSTart) return |
☞ 두 번째 방법 |
|
//=============================================== // 프로그램명 : 일정한 String로 분리된 String에서 N번째 String인출 // String gf_nth(Value string as_data, Value String as_Gubun, Value Integer al_nth) //=============================================== String ls_rtn Long ll_i, ll_strlen Long ll_f, ll_t
if isNull(as_data) or isNull(al_nth) then SetNull(ls_rtn) return ls_rtn end if
ll_f = 0 for ll_i = 1 to al_nth - 1 ll_f = Pos(as_data, as_Gubun, ll_f + 1) if ll_f = 0 then exit end if next
if ll_f = 0 and al_nth > 1 then SetNull(ls_rtn) return ls_rtn end if
ll_t = Pos(as_data, as_Gubun, ll_f + 1) if ll_t = 0 then ll_t = Len(as_data) + 1 end if
if al_nth = 1 then ls_rtn = String(Mid(as_data, ll_f + 1, ll_t - ll_f - 1)) else ls_rtn = String(Mid(as_data, ll_f + Len(as_Gubun), ll_t - ll_f - Len(as_Gubun) )) end if return ls_rtn |