Expecting identifier before left bracket - actionscript-3

I continue getting the following error:
Expecting identifier before left bracket
For the following line below.
Any ideas on how to solve this?
public var selectedEvents:[] = [];

If you're trying to create an array, it's public var selectedEvents:Array = [].

Related

Why do i get syntax error for return inside a function

I am trying to create a function that adds two random selected values from a list to another list. The updated list should be returned at the end.
This is what I wrote:
cards = [11,2,3,4,5,6,7,8,9,10,10,10,10]
user_hand = []
def add_cards(to_user, to_comp): {
user_hand.extend(random.choices(cards, k = to_user))
return user_hand
}
for some reason I 'invalid syntax' on the. Any ideas why?

Accessing element of a JArray -without Foreach loop

I'm developing an application where I receive a JSON array from an API. It has only one object. How do I access it in a single line syntax without using forEach loop?
object is inside array
[{"fiscalPeriod":8,"fiscalYear":2018,"calendarStart":"2018-02-11","calendarEnd":"2018-03-10"}]
Since you only have one item in the array you can get it out like this:
var array = [{"fiscalPeriod":8,"fiscalYear":2018,"calendarStart":"2018-02-11","calendarEnd":"2018-03-10"}];
var obj = array[0];
That square bracket syntax with the 0 in it says: give me the first item in the array.
Here some examples
var arr = [{"fiscalPeriod":8,"fiscalYear":2018,"calendarStart":"2018-02-11","calendarEnd":"2018-03-10"}];
console.log(arr[0].fiscalPeriod); // logs '8'
console.log(arr[0].fiscalYear); // logs '2018'
console.log(Object.keys(arr[0])); //["fiscalPeriod", "fiscalYear", "calendarStart", "calendarEnd"]
console.log(Object.keys(arr[0])[2]); //logs "calendarStart"

SSIS: How can I convert an NTEXT input to a string to perform a Split function in a script component?

I receive a Unicode text flat-file in which one column is a single fixed-length value, and the other contains a list values delimited by a vertical pipe '|'. The length of the second column and the number of delimited values it contains will vary greatly. In some cases the column will be up to 50000 characters wide, and could contain a thousand or more delimited values.
Input file Example:
[ObjectGUID]; [member]
{BD3481AF8-2CDG-42E2-BA93-73952AFB41F3}; CN=rGlynn SrechrshiresonIII,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3}; CN=reeghler Johnson,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp|CN=rCoefler Cellins,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp|CN=rDasije M. Delmogeroo,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp|CN=rCurry T. Carrollton,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp|CN=yMica Macintosh,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
My idea is to perform a Split operation on this column and create a new row for each value. I am attempting to use a script component to perform the split.
The width of the delimited column can easily exceed the 4000 character limit of DT-WSTR, so I chose NTEXT as the datatype. This presents problem because the .Split method I am familar with requires a string. I am attempting to convert the NTEXT to a string in the script component.
Here is my code:
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
var stringMember = Row.member.ToString();
var groupMembers = stringMember.Split('|');
foreach (var groupMember in groupMembers)
{
this.Output0Buffer.AddRow();
this.Output0Buffer.objectGUID = Row.objectGUID;
this.Output0Buffer.member = groupMember;
}
}
The output I am trying to get would be this:
[ObjectGUID] [member]
{BD3481AF8-2CDG-42E2-BA93-73952AFB41F3} CN=rGlynn SrechrshiresonIII,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} CN=reeghler Johnson,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} CN=rCoefler Cellins,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} CN=rDasije M. Delmogeroo,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} CN=rCurry T. Carrollton,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} CN=yMica Macintosh,OU=Users,OU=PRV,OU=LOL,DC=ent,DC=keke,DC=cqb,DC=corp
But what I am in fact getting is this:
[ObjectGUID] [member]
{BD3481AF8-2CDG-42E2-BA93-73952AFB41F3} Microsoft.SqlServer.Dts.Pipeline.BlobColumn
{AC365A4F8-2CDG-42E2-BA33-73933AFB41F3} Microsoft.SqlServer.Dts.Pipeline.BlobColumn
What might I be doing wrong?
The following code worked:
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
var blobLength = Convert.ToInt32(Row.member.Length);
var blobData = Row.member.GetBlobData(0, blobLength);
var stringData = System.Text.Encoding.Unicode.GetString(Row.member.GetBlobData(0, Convert.ToInt32(Row.member.Length)));
var groupMembers = stringData.Split('|');
foreach (var groupMember in groupMembers)
{
this.Output0Buffer.AddRow();
this.Output0Buffer.CN = Row.CN;
this.Output0Buffer.ObjectGUID = Row.ObjectGUID;
this.Output0Buffer.member = groupMember;
}
}
I was trying to perform an implicit conversion as I would in PowerShell, but was actually just passing some object metadata to the string output. This method properly splits my members and builds a complete row.

Stringify single and double quotes

With the following code I am creating an object to pass to a webservice. The single quote seems to be handled with a replace in the stringify before the object is passed to the service, but I don't know how to modify the double quote. If I inspect the Program.Comments field it would show the string like \"Word". This will cause an error in the stringify.
Is this an incorrect way to use the stringify for Json
Program = new Object();
Program.Field1 = $('#txtField1').val();
Program.Field2 = $('#ddlField2').val();
Program.Field3 = $('#lblField3').text();
Program.Field4 = $('#ddlField4').val();
Program.Field5 = $('#ddlField5').val();
Program.Field6 = $('#ddlField6').val();
// This field may contain both single and double quotes
Program.Comments = $('#txtComments').val();
Program.Field7 = $('#txtField7').val();
Program.Field8 = $('input[name=chbField8]').is(':checked');
// This will fix the issue of a single quote
vdata = JSON.stringify(Program).replace(/'/g, "\\'");d

AS3 Custom string formula parser

My goal is to create some kind of Parser to parse string formulas, similar to Excel formulas.
Formula string example (barcode example) -
"CONCAT('98', ZEROFILL([productNumber],5,'0'), ZEROFILL(EQUATION([weightKG]*1000),5,'0'))"
where
'98' - String
[productNumber] and [weightKG] - are variables that can be changed
CONCAT, ZEROFILL and EQUATION are methods which exist in class
For this formula with variables [productNumber] = '1' and [weightKG] = 0.1 result must be
'980000100100'
The question is how to split/parse whole string to parts and detect methods, variables and string values?
Another idea occurred, while i was typing - is to store whole formula in XML format.
Thank You.
You can use String.split() to get an array of substrings.
However, using your example, calling split(",") would give you the following array:
[0]=CONCAT('98'
[1]= ZEROFILL([productNumber]
[2]=5
[3]='0')
[4]= ZEROFILL(EQUATION([weightKG]*1000)
[5]=5
[6]='0'))
That doesn't seem like it will be very helpful for your project. Instead, you might think about creating a parse() function with some logic to find useful substrings:
function parse(input:String):Array {
var firstParen:int = input.indexOf("(");
var lastParen:int = input.lastIndexOf(")");
var formulaName:String = input.substring(0, firstParen);
var arguments:String = input.substring(firstParen, lastParen);
var argumentList:Array = parseArgs(arguments);
var result:Array = new Array();
result.push(formulaName);
//Recursively call parse() on the argumentList
foreach (var elem:* in argumentList) {
result.push(elem); //Could be string or array.
}
}
function parseArgs(input:String):Array {
// Look for commas that aren't enclosed inside parenthesis and
// construct an array of substrings based on that.
//A regex may be helpful here, but the implementation is left
//as an exercise for the reader.
}