เราสามารถแยกข้อความหรือ ตัวเลขที่เก็บในแบบสตริง ในรูปแบบ 1,2,3,4 เข้าไปใว้ในรูปแบบของ array ได้ โดยการเขียน ฟังก์ชั่น ในการแปลงรูปแบบ ดังต่อไปนี้
// Function Takes a CSV string and separates elements into an array
// Returns 0 = success
// 1 = error
//
// as_string Source string containing values delimited by as_delimiter
// as_array[] Destination array, passed by value
// ai_count Returns count of items in array
// as_delimiter delimiter value
int li_pos // position of commas
int li_len // string parsing
int li_start // string parsing
string ls_item // single item parsed from string
if Len ( as_string ) < 1 then
ai_count = 0
return 1
end if
// parse out items and insert into array
li_pos = 1
li_start = 1
ai_count = 0
DO WHILE li_pos > 0
li_pos = Pos ( as_string, as_delimiter, li_start )
if li_pos = 0 then
ls_item = Mid ( as_string, li_start )
else
ls_item = Mid ( as_string, li_start, li_pos - li_start )
end if
ls_item = Trim ( ls_item )
if Len ( ls_item ) > 0 then
ai_count++
as_array[ai_count] = ls_item
end if
li_start = li_pos + 1
LOOP
return 0
separate String แยกข้อความห เข้าไปใว้ในรูปแบบของ array
Latest News
- บทที่ 7-1 ตอน การสร้างระบบฐานข้อมูล
- บทที่ 6 ทดลองเขียนโปรแกรมด้วย PocketBuilder เบื้องต้น
- บทที่ 4 ติดตั้งdatabase sql anywhere
- บทที่ 7-2 ตอน การสร้างโปรแกรมแสดงรายการอาหารที่สั่ง ด้วย Powerbuilder 9
- บทที่ 3 ติดตั้งอุปกรณ์ และโปรแกรม Active Sync
- ทำชุด setup โปรแกรมด้วย Wise Install
- การติดตั้ง IIS
- ตัวอย่าง code โปรแกรมร้านเช่า VDO
- สมาชิก : 2
- Content : 336
- เว็บลิงก์ : 8
- จำนวนครั้งเปิดดูบทความ : 158884


