Remove some special character "[ ]" from a string - actionscript-3

I'm new to flex coding, for example if I have a string like "[123-456],[456-789]"
and I want to remove all the "[" and "]" which result in:
"123-456,456-789"
can string.replace() or trim() do the job for me?
tried several times still fail

In this case string.replace() should do the job!
Please see the documentation for String.replace()
var st: String = "[123-456],[456-789]";
var p1: RegExp = /\[|\]/g;
st = st.replace(p1, "");
trace(st) //"123-456,456-789"

Related

remove [" from string is SSIS using derived column

I am trying to remove [" from beginning of the string and "] end of the string by using REPLACE function in derived column. But it is giving an error.
I have used the below formula
REPLACE(columnanme,"["","")
is used in the to remove [" in the beginning of the string. But not working.
Can someone help me on this.
Note: Data is in table and datatype is NTEXT
Regards,
Khatija
I believe you just need to escape the " value
so
\”
REPLACE(columnanme,"[\"","")
otherwise it sees the " in the middle as the closing quote and you have an invalid statement.
I am trying to remove [" from beginning of the string and "] end of the string
Supposing that we reliably have brackets and quotes wrapping the data, the simplest approach would be to use substring. This would be easier to do in SQL:
UPDATE myTable SET columnname = SUBSTRING(columnname, 3, LEN(columnname) -4)
WHERE columnname LIKE '["%"]'
If you want to do this in SSIS, you'll need to use a script component transformation to avoid data loss when converting the value to a string. Select the column you want to work with and set the usage type to ReadWrite:
In the script, I have added a method GetNewString, which converts the blob to a string and strips the unwanted characters. You can also use Replace or Regex.Replace if that makes more sense.
In the Input0_ProcessInputRow method, we convert the columns data, reset the blob and then add the new value:
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
var input = GetNewString(Row.columname);
Row.columname.ResetBlobData();
Row.columname.AddBlobData(System.Text.Encoding.Unicode.GetBytes(input));
}
public string GetNewString(Microsoft.SqlServer.Dts.Pipeline.BlobColumn blobColumn)
{
if (blobColumn.IsNull)
return string.Empty;
var blobData = blobColumn.GetBlobData(0, (int)blobColumn.Length);
var stringData = System.Text.Encoding.Unicode.GetString(blobData);
stringData = stringData.Substring(2, stringData.Length - 4);
return stringData;
}

How to use variable in JMESPath expression?

The regular expression works perfect as below:
jmespath.search(currentStats, 'Items[?Name == Annie]')
But I want to make my filtered key as a variable.
I have tried
var name = "Annie"
jmespath.search(JSONdata, 'Items[?Name == %s]' %name;)
Which does not work.
Many thanks in advance.
There's no built-in way in jmespath or the search function to template values into the query string, but you can safely embed JSON literals with backticks, however your language allows it.
var name = "Annie";
var result = jmespath.search(JSONdata, 'Items[?Name == `' + JSON.stringify(name).replace('`','\\`') + '`]');
We need to convert the string to JSON, escape any backticks in that string and then wrap it in backticks. Let's wrap that into a function to make it a bit nicer to read:
function jmespath_escape(item) {
return '`' + JSON.stringify(item).replace('`','\\`') + '`';
}
var name = "Annie";
var result = jmespath.search(JSONdata, 'Items[?Name == ' + jmespath_escape(name) + ']');

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

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

How to get rid of new line character in a string, ActionScript3

I want to remove the new line character in a string, I tried to use something like:
myString.replace('\n', '');
But this doesn't work. What's the best way to do it?
A new string is returned, it is not modified in-place.
myString = myString.replace('\n', '');
If you have multiple newlines, you'll need to use a RegExp with the g flag set.
myString = myString.replace(new RegExp('\\n', 'g'), '');
And if you don't want to use RegExp you can simply use split and join:
myString = myString.split('\n').join('');

String.replace() function to parse XML string so that it can be displayed in HTML

I have a XML string which needs to be displayed within HTML. I understand the first thing needed to be done here is to convert all '<' and '>' into '& lt;' and '& gt;' (ignore the space after & sign). This is what I am doing to replace '<' -
regExp = new RegExp("/</g");
xmlString = xmlString.replace(regExp, '& lt;');
xmlString does not change.
Also, trace(regExp.test("<")); prints false.
What is wrong here?
replace returns a new string, it doesn't modify the old one. So if you want to overwrite the old you have to do the following:
xmlString = xmlString.replace(regExp, '<');
Or if you don't want to overwrite the old one, just store the result in a new variable.
var newString = xmlString.replace(regExp, '<');
The issue is the way you create your RegExp object.
Because your using the RegExp constructor, don't include the / characters:
regExp = new RegExp("<", "g");
or use / as a shortcut:
regExp = /</g;
See this page for more details: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/RegExp.html