Variable Defining As String - actionscript-3

var allMatches:Number = soloStats[0] + duoStats[0] + squadStats[0]
When I try to make this variable a number, allMatches is a number but the values in it join as a string (for example 1, 2, and 3 join together as 123 instead of 6).
All the stats values are numbers and are successfully used at other times as a number, however in this variable they act like strings.

This is because you store the numbers as strings in your array.
You can use parseInt to get a number from a string
const allMatches = parseInt(soloStats[0]) + parseInt(duoStats[0]) +
parseInt(squadStats[0])

Related

Finding the number of times a name is in a string

string = "Hamza flew his kite today. But Hamza forgot to play basketball"
def count_name():
count = 0
for sub_str in string:
if sub_str == "Hamza":
count += 1
return count
print(count_name())
My goal here was to find the number of times the name "Hamza", appears in the string.
But it keeps returning 0, instead of 2.
I tried setting the variable count = 0, so it can count how many times the name "Hamza" appears in the string.
The countName function takes a string as an argument and returns the number of times "Hamza" appears in it. Here is one way to count the number of times "Hamza" appears in a given string:
function countName(str) {
let count = 0;
let index = str.indexOf("Hamza");
while (index != -1) {
count++;
index = str.indexOf("Hamza", index + 1);
}
return count;
}
let string = "Hamza flew his kite today. But Hamza forgot to play basketball";
let count = countName(string);
console.log(count); // Output: 2
when you do for sub_str in string: you are looking at one letter a time (not one word at a time). You are checking...
'H'=='Hamza' which returns False
'a'=='Hamza' which returns False
'm'=='Hamza' which returns False...
that is why your count will never increase.
Luckily for you python has built in methods to make your life easy.
Try string.count('Hamza')

extract date from file name using SSIS expression

HT,
Using Microsoft SSIS.
I have a input CSV file called - LatLong_WD_Locations_06-21-2021.
I want to extract date from this file name in 20210621 format using SSIS expression and store in to a variable called v_FileDate which is Int32 type.variable v_FileName is a string type.
I tried with
(DT_I4) REPLACE(SUBSTRING( #[User::v_FileName],FINDSTRING( #[User::v_FileName] , "_", 2)+1,10),"-","")
but its not working.
Can I have some help here, please.
TIA
Almost there. You specified 2 for the occurrence argument in FINDSTRING expression. So it is finding the _ before Location in the file name giving you a result of Locations_. Since that is not a integer it is throwing an error.
Change the 2 to a 3:
(DT_I4) REPLACE(SUBSTRING( #[User::v_FileName],FINDSTRING( #[User::v_FileName] , "_", 3)+1,10),"-","")
The above would account for if the V_FileName has a file extension. It would not get you the final format of yyyyMMdd. See below...
You could also simplify and use RIGHT expression. Get the right 10 characters of the string and then replace:
(DT_I4) REPLACE(RIGHT(REPLACE(#[User::v_FileName], ".csv",""), 10),"-","")
I updated the above statement to account for if v_FileName had an extension. That still does not give your final format of yyyyMMdd. See below...
Those 2 expressions above will get the date out of the v_FileName, but in format MMddyyyy. Now you will have to parse out each part of the date and put it back together using one of the above statements. The example below is using the one with RIGHT:
(DT_I4) SUBSTRING(REPLACE(RIGHT(REPLACE(#[User::v_FileName], ".csv",""), 10),"-",""), 5,4)
+ SUBSTRING(REPLACE(RIGHT(REPLACE(#[User::v_FileName], ".csv",""), 10),"-",""), 1,2)
+ SUBSTRING(REPLACE(RIGHT(REPLACE(#[User::v_FileName], ".csv",""), 10),"-",""), 3,2)
If you ever have Date on the last 10 positions in file name solution is very simple. But if that is not case, write me below in a comment and I will write a new expression.
Solution explained step by step:
Get/create variable v_FileDate with value LatLong_WD_Locations_06-21-2021
For check create DateString with expression
RIGHT( #[User::v_FileDate], 4) +
LEFT (RIGHT( #[User::v_FileDate], 10), 2) +
LEFT (RIGHT( #[User::v_FileDate], 7), 2)
Create a final variable DateInt with expression
(DT_I4) #[User::DateS]
How variable should like:
Or you can with a single variable (It would be better with a single variable).
(DT_I4) (
RIGHT( #[User::v_FileDate], 4) +
LEFT (RIGHT( #[User::v_FileDate], 10), 2) +
LEFT (RIGHT( #[User::v_FileDate], 7), 2)
)
Final Result
Using script task...
Pass in v_FileDate as readwrite
Pass in v_FileName as readonly
Code:
//Get filename from SSIS
string fileName = Dts.Variables["v_FileName"].Value;
//Split based on "_"
string[] pieces = fileName.Split('_');
//Get the last piece [ref is 0 based and length is actual]
string lastPiece = pieces[piece.Length -1];
//Convert to date
DateTime d = DateTime.ParseExact(lastPiece, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);
//Convert to int from string converted date in your format
Dts.Variables["v_FileDate"].Value = int.Parse(d.ToString("yyyyMMdd"));
Some work around -Working for me in (YYYYMMDD) format.
Thanks #keithL
(DT_I4)( REPLACE(RIGHT(#[User::v_FileName], 5),"-","")+REPLACE(SUBSTRING( #[User::v_FileName],FINDSTRING( #[User::v_FileName] , "", 3)+1,2),"-","")+REPLACE(SUBSTRING( #[User::v_FileName],FINDSTRING( #[User::v_FileName] , "", 3)+3,4),"-",""))

Fetch records with query Args in Go

I Need help for fetch records from table using Go.
My Problem is that i'm writing MySQL query and add another where clause i.e HPhone number, Here HPhone number inserted in data base with format like 999-999-9999.And i passed this HPhone Number in format like 9999999999. which is not matching with correct data base field value. And i used SUBSTRING for add hyphen between numbers but it does not get records but when i passed like 999-999-9999 without SUBSTRING it return records.
Here i demonstrate how i used this.
strQry = `SELECT * from table WHERE Depot = ?`
if HPhone != "" {
strQry += ` AND HPhone = ?`
}
queryArgs := []interface{}{RouteAvailability.Depot}
if HPhone != "" {
queryArgs = append(queryArgs, "SUBSTRING("+HPhone+",1,3)"+"-"+"SUBSTRING("+HPhone+",4,3)"+"-"+"SUBSTRING("+HPhone+",7,4)")
}
Help would be appreciated.
Thanks in advance.
Instead of SUBSTRING you can use REPLACE like so:
queryArgs := []interface{}{RouteAvailability.Depot}
if HPhone != "" {
strQry += ` AND REPLACE(HPhone, '-', '') = ?`
queryArgs = append(queryArgs, HPhone)
}
If possible I would suggest you normalize your data, i.e. decide on a canonical format for a particular data type and everytime your program receives some input that contains that data type you format it into its canonical form, that way you can avoid having to deal with SUBSTRING, or REPLACE, or multiple inconsistent formats etc.
This won't work as you are using prepared statements, and the argument you are building when HPhone is not empty will be used in escaped form - so when executing the query, it won't compare the HPhone values with the computed result of some substring, but with a string containing SUBSTRING(9999...

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.

Format number Rdlc report

i need to show numbers 1 2 3 in Arabic letters
i write in text box expression this statement
=FormatNumber(Fields!Size.Value,1,-2,-2,-2)
but i don't know it's parameter and which parameter can show numbers in Arabic format
MANY THANKS
set report language to your local language (ar-EG)
in the textbox properties set NumeralVariant to 3
references
similar problem
NumeralVariant
limitations
1- will not work for strings containing numbers
2- will not work for dates
work around limitation with bad performance i guess
you can replace any english number with arabic number using Replace method in any string that may contain numbers
your expression will be some thing like this
=Replace(Replace(Replace(Fields!FieldName.Value,"0","۰"),"1","۱"),"2","۲")
complete expression to 9
You can write function in code and use that
enter image description here
Public Shared Function farsi(input As String) As String
Dim result As String = input
result = result.Replace("1", "۱")
result = result.Replace("2", "۲")
result = result.Replace("3", "۳")
result = result.Replace("4", "۴")
result = result.Replace("5", "۵")
result = result.Replace("6", "۶")
result = result.Replace("7", "۷")
result = result.Replace("8", "۸")
result = result.Replace("9", "۹")
result = result.Replace("0", "۰")
Return result
End Function
Usage:
=Code.farsi(1111.555)
Public Shared Function Arabic(input As String) As String
Dim result As String = input
result = result.Replace("1", "۱")
result = result.Replace("2", "۲")
result = result.Replace("3", "۳")
result = result.Replace("4", "٤")
result = result.Replace("5", "۵")
result = result.Replace("6", "٦")
result = result.Replace("7", "۷")
result = result.Replace("8", "۸")
result = result.Replace("9", "۹")
result = result.Replace("0", "۰")
Return result
End Function
Use it for arabic Numbers
=Code.Arabic(Fields!OrderID.Value)
=Code.Arabic(FieldName)