AS3 | How to remove letters drom string and remain only integer - actionscript-3

How to remove letters drom string and remain only integer?
Example:
input: item_Maps_4
output: 4

You can use regex on your string:
var str:String = "item_Maps_4";
str = str.replace( /[a-zA-Z\_]/g, "" );
That will get rid of all the letters and underscores

If you want to get the number from output(question is not clear) then you can do
var value:String=text.split(":")[1];
you may need to trim the result and if you need it as an int use parseInt function

Related

Checking for special character in JSON string with Everit and regex [duplicate]

What is the regular expression (in JavaScript if it matters) to only match if the text is an exact match? That is, there should be no extra characters at other end of the string.
For example, if I'm trying to match for abc, then 1abc1, 1abc, and abc1 would not match.
Use the start and end delimiters: ^abc$
It depends. You could
string.match(/^abc$/)
But that would not match the following string: 'the first 3 letters of the alphabet are abc. not abc123'
I think you would want to use \b (word boundaries):
var str = 'the first 3 letters of the alphabet are abc. not abc123';
var pat = /\b(abc)\b/g;
console.log(str.match(pat));
Live example: http://jsfiddle.net/uu5VJ/
If the former solution works for you, I would advise against using it.
That means you may have something like the following:
var strs = ['abc', 'abc1', 'abc2']
for (var i = 0; i < strs.length; i++) {
if (strs[i] == 'abc') {
//do something
}
else {
//do something else
}
}
While you could use
if (str[i].match(/^abc$/g)) {
//do something
}
It would be considerably more resource-intensive. For me, a general rule of thumb is for a simple string comparison use a conditional expression, for a more dynamic pattern use a regular expression.
More on JavaScript regexes: https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions
"^" For the begining of the line "$" for the end of it. Eg.:
var re = /^abc$/;
Would match "abc" but not "1abc" or "abc1". You can learn more at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

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.

How to make a path with a String name into a simple String

How do i make the path of the item and its name that is given within the "" into a simple string
what i mean is:
when i just do this
var myText:String = new String("pathToImage")
trace(myText)
in the outPut window I get this : pathToImage.And that is Ok
But can i put double quotes into a string, like this
var myText:String = new String(" pathToImage("ImageName") ")
trace(myText)
and in the outPut window to get this : pathToImage("ImageName")
cause I'm trying this way, but it givems me an error:
1084: Syntax error: expecting rightparen before ImageName.
So is there a way of doing this?
First of all, it’s enough if you just use string literals. You do not need to call the String constructor:
var myText:String = "pathToImage";
Second, string literals are either quoted with double quotes " or single quotes '. If you want the quotation character itself as a part of the string, you need to escape it using the escape character \. So if you want to have a string pathToImage("ImageName"), then you will have to do it like this:
var myText:String = "pathToImage(\"ImageName\")";
Alternatively, you can also use single quotes here. Using single quotes as the string delimiter allows you to use double quotes within the string without having to escape them. The same applies to single quotes within double-enquoted strings:
var myText:String = 'pathToImage("ImageName")';

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)

Is there a function to test if a String variable is a number value?

Is there a way to test a string, such as the one below to see if it's an actual number value?
var theStr:String = '05';
I want to differentiate between the string value above and one such as this:
var theStr2:String = 'asdfl';
Thanks!
Yes use isNaN function to test if it the String is a valid Number:
var n:Number=Number(theStr);
if (isNaN(n)){
trace("not a number");
} else {
trace("number="+n);
}
You must cast to Number to get is NaN. If you use int letters can be cast to 0.
If you are just interested in checking integers you could use the match function as follows, the regex for numbers is more complicated and you would likely be better off following the casting method Patrick provided.
if (s.match(/^\d+$/)){//do something}
Of course if you are going to need to cast it anyway then using isNaN makes perfect sense. Just thought I'd offer an alternative in case you weren't going to cast it.
This code will return true if s contains only digits (no spaces, decimals, letters etc...) and requires there be at least 1 digit.