Re: Advanced regexp again by Steve
Steve
Fri Apr 08 09:32:28 CDT 2005
Lasse Edsvik wrote:
> Hello
>
> I want to ask for mr regexp steve for help again :)
>
> I have this:
>
> Menu2=new Array("Apple sauce","some url here","",6,16,160);
> Menu2_1=new Array("Pigs on dope","something","",0,16,160);
> Menu2_2=new Array("Trees","somethi/...?9ng else","",0,16,160);
This looks suspiciously like JScript. Do you mean:?
Menu2=Array("Apple sauce","some url here","",6,16,160)
Menu2_1=Array("Pigs on dope","something","",0,16,160)
Menu2_2=Array("Trees","somethi/...?9ng else","",0,16,160)
Anyway, regular expressions work on *strings*, not *arrays*.
> I need to extract 3 things on each row $1 $2 $3 (?)
>
> Menu2 Apple sauce some url here
>
> in the first and:
>
> Menu2_1 Pigs on dope something
> Menu2_2 Trees somethi/...?9ng else
>
> is this possible to do? seem impossible :(
Well, you can get the second and third things by accessing the
array elements Menu2(0) and Menu2(1). However, besides the simalar
names and the same structure, the three arrays have no relation
to each other. You'd have to explicitly reference each array
separately (e.g. Menu2(0), Menu2_1(0), etc.).
You probably want a more robust data structure to contain all
the elements; not separate data structures to contain some of
the elemenst.
You could use a 2-dimensional array:
Dim Menus(2, 6)
Menus(0,0)="2" : Menus(0,1)="Apple sauce" : Menus(0,2)= ...
Menus(1,0)="2_1" : Menus(1,1)="Pigs on dope" : Menus(1,2)= ...
Menus(2,0)="2_2" : Menus(2,1)="Trees" : Menus(2,2)= ...
NOTE: JScript doesn't have arrays of greater than 1 dimension.
You have to use an array of arrays.
var menus = [
["2","Apple sauce","some url here","",6,16,160],
["2_1","Pigs on dope","something","",0,16,160],
["2_2","Trees","somethi/...?9ng else","",0,16,160]
]
You could use a disconnected recordset:
Set Menus = CreateObject(ADODB.Recordset")
Menus.Fields.Add "Menu", 200, 255
Menus.Fields.Add "String1", 200, 255
Menus.Fields.Add "String2", 200, 255
Menus.Fields.Add "String3", 200, 255
Menus.Fields.Add "Number1", 3
Menus.Fields.Add "Number2", 3
Menus.Fields.Add "Number3", 3
With Menus
.AddNew
.Fields("Menu").Value = "2"
.Fields("String1").Value = "Apple sauce"
' ...
.Fields("Number3").Value = 160
.AddNew
.Fields("Menu").Value = "2_1"
.Fields("String1").Value = "Pigs on dope"
' ...
End With
You could use a dictionary object:
Set Menus = CreateObject("Scripting.Dictionary")
With Menus
.Add "2", Array("Apple sauce","some url here","",6,16,160)
.Add "2_1", Array("Pigs on dope","something","",0,16,160)
.Add "2_2", Menu2_2=Array("Trees","somethi/...?9ng else","",0,16,160)
End With
NOTE: Although you can use a dictionary object in JScript, it's simpler
to use an Object object:
var menus = {
Menu2: ["Apple sauce","some url here","",6,16,160],
Menu2_1: ["Pigs on dope","something","",0,16,160],
Menu2_2: ["Trees","somethi/...?9ng else","",0,16,160]
}
--
Steve
Holding on to anger is like grasping a hot coal with the intent of
throwing it at someone else; you are the one getting burned. -Buddha