splitting a string in as3 - actionscript-3

i have several strings that look like this:
contactBtn, programBtn, cartBtn.
How can i split these strings so that the "btn" gets discarted, so i keep contact, program, cart.
How would i achieve this?

The String class has a replace method:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html

Check out the Replace() Section of the ActionScript 3.0 Documentation.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#match%28%29
var yourString:String = “contactBtn”
yourString= yourString.split(“Btn”).join(“”);
trace(yourString);
// Output : yourString = "contact"
You would just have to iterate through all of your buttons.

You can also use RegExp :
trace(/.+(?=btn$)/gi.exec("foobtn"));//foo
trace(/.+(?=btn$)/gi.exec("fooBTN"));//foo
trace(/.+(?=btn$)/gi.exec("barbtn"));//bar
trace(/.+(?=btn$)/gi.exec("bar"));//null

Related

Check and print occurrences of an array of string in a dataset in Python

I want to check if an array of strings occur in a dataset and print those rows where the string array elements occur.
rareTitles = {"Capt", "Col", "Countess", "Don", "Dr", "Jonkheer", "Lady",
"Major", "Mlle", "Mme", "Ms", "Rev", "Sir"}
dataset[rareTitles in (dataset['Title'])]
I am getting following error:
TypeError: unhashable type: 'set'
First of all, I think the comparison should go the other way around - you look for a dataset['Title'], that contains string from rareTitles.
You can use str attribute of a pandas DataSeries, which allows as to use string methods, like contains. As this method accepts also a pattern as a regular expression, you can put as an argument something like 'Capt|Col...'. To join all elements of a set you can use str.join() method.
So the solution would be
dataset[dataset['Title'].str.contains('|'.join(rareTitles))]
Link to documentation: pandas.Series.str.contains

how to use [ngClass] for multiple class conditions Angular4

currently my div looks like this:
<div class="class-a" [ngClass]="{'class-b': !person.something}">
now I want to have another condition...
so now I want this div to be of class-a If something class-b If something else class-c
how should I do this?
im using angular 4.
thanks!
Add it like properties to an object literal:
[ngClass]="{'class-b': !person.something, 'other-condition': isOther }"
Another option is to return a string from the component if you think you need more complex logic, or know there will only be one. This might be more testable.
Whatever string you return will be rendered as a class(es)
[ngClass]="renderClass()"
renderClass() {
switch(this.user.theme){
case "dark":
return "dark-theme"
case "light":
return "light-theme"
}
}
The better way for use this Syntax ngStyle Because,
it's Not Completed Answer.
If you want to toggle some classes like text-info Or text-danger for <i> tag (
some exp ? 'text-info' : 'text-danger'
).
The best answer is array not object.
[ngClass] = "[some exp ? 'text-info' : 'text-danger', ...]"
GoodLuck

Use string as a JSON command

I have this string:
var test = "toAdd";
I want to use it to extract data from JSON, like:
console.log(value.stats.test);
As you see, test is not correct, as it is just a string and can't be used, it is just not recognized at all. How do I make it recognize?
What you are attempting to do is this:
var someVar;
someVar.test = 'Sample';
someVar.test.attribute = 'Another sample';
// this:
console.log(someVar['test']['attribute']);
// will produce the same as this:
console.log(someVar['test'].attribute);
// as well as the same as this:
console.log(someVar.test['attribute']);
This will print "Another sample".
This has nothing to do with JSON. This is just javascript, and like anything where the . notation won't work switch to array notation:
foo.bar.baz = 'qux';
alert(foo['bar'].baz); // popup with 'qux'
^-----^-- note these
In your case, value.stats[test]. Now "test" isn't an array key, it's a variable whose value gets used as the key.

Displaying an array comma-separated in jade?

I want to display an array in Jade separated by commas instead of line which I currently have how can I do this? This is segment of code I need help with players being the array passed from javascript
p Currently playing:
ul
each theExit in players
p #{theExit}
Assuming that players is an array of String's you can use following statement:
p Currently playing: #{players.join(', ')}
That will give you something like (assuming you had 3 entries in the array: player1, player2 and player3):
<p>Currently playing: player1, player2, player3</p>
I hope that will help.
Supposed you were working with not plain String arrays and your data is something like below:
{
[_id: 1, name: 'player1'],
[_id: 2, name: 'player2'],
[_id: 3, name: 'player3'],
}
Then you could probably just use:
each player, index in players
if index === players.length -1
| #{players.name}
else
| #{players.name},
NOTE: Not really the cleanest solution out there but does the job. Use at your own disposal. :)
If you have an array of objects and you want a comma-separated list of a property of each object, I went with:
- var playerList = players.map(player => player.name).join(', ')
p Currently playing: #{playerList}

iterate through JSON array with mustache

I am new to Mustache, please bear with me :)
I have an array in my JSON
"prop":{"brands":["nike","adidas","puma"]}
if I have the template like this
{{#prop}}
<b>{{brands}}</b>
{{prop}}
and I want to get something like:
<b>nike</b>
<b>adidas</b>
<b>puma</b>
I understand the elements in the array are not hash key-value pairs, however I am wondering if there is anyway in mustache that I can iterate through the elements.
Thanks!
Here is a working fiddle: http://jsfiddle.net/Qa4UX/
Basically, you need to iterate over the brands array.
Since your array is raw and does not have objects inside you have to reference each string like so:
{{#props}}
<ul>
{{#brands}}
<li>
{{#.}}
<b>{{.}}</b>
{{/.}}
</li>
{{/brands}}
</ul>
{{/props}}
You can also find many more examples over here: https://github.com/janl/mustache.js#mustachejs---logic-less-mustache-templates-with-javascript
This works
{{#json.props.brands}}
<h1>{{.}}</h1>
{{/json.props.brands}}
{{.}} When looping over an array of strings, a . can be used to refer to the current item in the list.
mustache is logicless, so writing your own iteration/loop in it is impossible. It is easy to convert your JSON though. For example:
var json = '{"prop":{"brands":["nike","adidas","puma"]}}';
var obj = JSON.parse(json);
var data = {brands: obj.prop['brands'].map(function(x){ return {name: x}; })};
Gives you a data variable which will work with the template:
{{#brands}}
<b>{{name}}</b>
{{/brands}}