Jump to content

help with how to get these values in to arrays


Recommended Posts

hi all

i would like to ask that how to get these values in to arrays

first i get a string wich like:

$a='501*3.8|502*3.8|503*3.81|504*1995|505*2008|506*2010|508*10/08/2008 12:10:00|509*4.2|510*3.8|511*3.9'

and i know can use function stringsplit()

like

$a=stringsplit("501*3.8|502*3.8|503*3.81|504*1995|505*2008|506*2010|508*10/08/2008 12:10:00|509*4.2|510*3.8|511*3.9", "|")

i want use arrary to get the values which after 501* and end with "|"

after that i will get like this

$avarray[0]="3.8"

$avarray[1]="3.8"

....

$avarray[7]="10/08/2008 12:10:00"

$avarray[8]="3.8"

$avarray[9]="3.9"

many thanks ~^^

Link to comment
Share on other sites

$sSource = "501*3.8|502*3.8|503*3.81|504*1995|505*2008|506*2010|508*10/08/2008 12:10:00|509*4.2|510*3.8|511*3.9"
$avarray = StringRegExp($sSource, "\d\*(.+?)\|", 3)
For $iX = 0 To UBound($avarray) - 1
    ConsoleWrite("$avarray[" & $iX & ']="' & $avarray[$iX] & '"' & @CRLF)
Next
Output:
$avarray[0]="3.8"
 $avarray[1]="3.8"
 $avarray[2]="3.81"
 $avarray[3]="1995"
 $avarray[4]="2008"
 $avarray[5]="2010"
 $avarray[6]="10/08/2008 12:10:00"
 $avarray[7]="4.2"
 $avarray[8]="3.8"

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

can i get only $array[2] & $array[6] 's value

Probably, but it all depends on what criteria you want to use to do such filtering.

Are you looking solely at their positions in the string?

If so, a regexp could be formulated but it's much easier to use $avarray[2] and $avarray[6].

Are the 503* and 508* parts significant?

The "patterns" I see here that don't apply to the other entries are:

$avarray[2]="3.81" has two decimal places while the others only have one.

$avarray[6]="10/08/2008 12:10:00" contains slashes, colons, and spaces.

$avarray[6]="10/08/2008 12:10:00" is longer than 4 characters.

These questions would need to be answered in order to seek a robust solution.

This is the closest I can get, but there's an extra empty match:

$sSource = "501*3.8|502*3.8|503*3.81|504*1995|505*2008|506*2010|508*10/08/2008 12:10:00|509*4.2|510*3.8|511*3.9"
$avarray = StringRegExp($sSource, "\d\*(\d\.\d{2})|(\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2})\|", 3)
For $iX = 0 To UBound($avarray) - 1
    ConsoleWrite("$avarray[" & $iX & ']="' & $avarray[$iX] & '"' & @CRLF)
Next

Output:

$avarray[0]="3.81"
   $avarray[1]=""
   $avarray[2]="10/08/2008 12:10:00"

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

i got an other way

$a=stringsplit("'501*3.8|502*3.8|503*3.81|504*1995|505*2008|506*2010|508*10/08/2008 12:10:00|509*4.2|510*3.8|511*3.9'", "|")
for $i=1 to UBound($a)-1
        $b=StringRegExp($a[$i],'(?<=\d{3}\*).+',2)
        MsgBox(0,0,$b[0])
Next

this can show each values which i want

but i do know how to put them in $arrary[0] ~[9]

and show only only $array[2] & $array[6] 's value yet

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...