Actionscript :: Case Statement String With Regex?
Nov 2, 2010I see Switch statement in:
switch() {
case 'string': ...;
}
but would hope if I could do this?
I see Switch statement in:
switch() {
case 'string': ...;
}
but would hope if I could do this?
In Actionscript and Adobe Flex, I'm using a pattern and regexp (with the global flag) with the string.match method and it works how I'd like except when the match returns multiple occurrences of the same word in the text. In that case, all the matches for that word point only to the index for the first occurrence of that word. For example, if the text is "cat dog cat cat cow" and the pattern is a search for cat*, the match method returns an array of three occurrences of "cat", however, they all point to only the index of the first occurrence of cat when i use indexOf on a loop through the array. I'm assuming this is just how the string.match method is. I want to find the specific indices of every occurrence of a match, even if it is of a word that was already previously matched.
how the string.match method is and if so
Trying to replace a portion of a string with a "-" if it matches a string variable in AS3.
var re:RegExp = new RegExp(imageArray[j][1],"gi"); trace(imageArray[jTemp][2].replace(re,"-"));
imageArray[jTemp][2] is a string imageArray[j][1] is a string as well I'm not getting the result I expect. I would like trace above to return 'permanentContainer-' Here are the traces for the above variables
permanentContainer-temporaryContainer- temporaryContainer
I am trying to get my pages through Case Statement But.
[Code]...
I'm trying to use the value from a combo box in a switch case statement but it isn't working
Code:
var switchValue:int = 0;
switchValue = int(cmbColour.selectedItem.data);
switch(switchValue) {[code]....
I've got a slider on my navigation bar that rides along with the mouse; movies play perpendicular to it as I scroll. If I click on the movie, I link out to another page (easy enough). However, the actual slider doesn't do anything more than look nice. I know that if I don't make this thing child proof, I'm going to catch grief about it. So I tried to set up a switch that links out according to range values y<0 && y>125. As it stands, I don't get any errors, it just always goes to default. I'm missing something.I could always try a gia-normous 'if' statement, but I thought that I'd give the switch a try.
View 4 RepliesI'm trying to use switch/case staement instead of if/else but it's not working. Here's the code.
ActionScript Code:
//working code
function checkTarget(drag){[code].............
How do you do a range using switch statement in ActionScriptFor example:
score = txtScore.text
switch(score)
{
[code].....
How do you do a range using switch statement in ActionScript For example:
[Code]...
Is there such thing as a "select case" statement in actionscript? If there is what is its format?
View 2 RepliesI'm trying to work with RegEx to split a large string into smaller sections, and as part of this I'm trying to replace all instances of a substring in this larger string. I've been trying to use the replace function but this only replaces the first instance of the substring. How can I replace al instances of the substring within the larger string?
View 3 RepliesI have a large group of functions.The function to be called depends on the value of a var (which is a int);I could make a long case statement along the lines of this
PHP Code:
var Pos:int = 0;function test1():void{ trace("Test 1");}function test2():void{ trace("Test 2");}function test3():void{ trace("Test
[code]....
I am trying to figure out how to apply the is operand or the instanceof in a case statement to determine which datatype a interface object belongs too. keep getting errors
switch (IOjbect is)
{
case Tile:
[code].....
I can't for the life of me come up with anything that works...
function setCurrentCMI(id){
if (_level0.strInteraction+id==""||_level0.strInterac tion+id=="undefined") {
//does nothing, user hasn't been here yet
[code]......
I've been creating an application using the Adobe AIR Packager for iPhone (command line style).The app consists of a lot of screens that provide various information, and the navigation is handled all in the document class via an event-triggered function that uses a large switch-case statement to determine what screen to go to.
When we compiled it through the iPhone Packager and tried to test it on one of our phones, it would load up to a blank screen.
After some error testing it was revealed that the switch-case itself is causing a problem (changing it to an if-else that had the same functionality worked just fine). Does anyone know whether this is a known issue, or if something can be done to fix that other than converting it to an if-else.
How i write the inline conditional statement in Flex with two expressions(case) [code]...
Flex compiler only check the first expression and on behalf of that give result.But i want to check both statement and show result.
I have absolutely no knowledge in Regex whatsoever. Basically what I'm trying to do is have an error class that I can use to call errors (obviously) which looks like this:
package avian.framework.errors
{
public class AvError extends Object
{
[Code].....
The idea is to replace {0} with the first parameter parsed in ...params, {1} with the second, etc.
I've done a bit of research and I think I've worked out that I need to search using this pattern:
var pattern:RegExp = /{d}/;
I have a text field within Flash that contains a block of (obviously) text. What I want to do is perform a search on the content of the text field that returns the x & y coordinate and the width & height of the found text. The result will be used to place a visual element over that portion of the text box.
For example:
var pattern:RegExp = /d+/g;
var found:Array = box.text.match(pattern);
var i:String;
for each(i in found) {
/**
* Find the x, y, width, height of the matched text in the text field
* Use result to place transparent yellow box around text
*/
}
Which visually should result in something like:
I am trying to find the generic links in strings. I've found a very handy regex on RegExr, in the community expressions:
(https?://)?(www.)?([a-zA-Z0-9_%]*).[a-z]{2,4}(.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(.[a-z]*)?(:d{1,5})?
I tried to use it and it returns null, although the same string tested on RegExr works fine:
var linkRegEx:RegExp = new RegExp("(https?://)?(www.)?([a-zA-Z0-9_%]*).[a-z]{2,4}(.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(.[a-z]*)?(:d{1,5})?","g");
var link:String = 'generic links: www.google.com http://www.google.com google.com';
[code]....
I have a string that is similar to a path, but I have tried some regex patterns that are supposed to parse paths and they don't quite work.
Here's the string
f|MyApparel/Templates/Events/
I need the "name parts" between the slashes.
I tried (w+) but the array came back [0] = "f" and [1] = "f".
I tested the pattern on [URL] and it seems to work correctly.
Here's the AS code:
var pattern : RegExp = /(w+)/g;
var hierarchy : Array = pattern.exec(params.category_id);
params.name = hierarchy.pop() as String;
I have some ActionScript code that splits a string using Regular Expression and lets me add content at the split location.
// AS3 Code
function formatTweetText(tweet:String ):String
{
[code]....
I'm new to actionscript and i cant seem to get the regex syntax right in actionscript3. The task is straight forward, i want to make sure that the first two characters in a given string are alphabets and nothing else.[code]
View 2 RepliesI don't know anything about regular expressions and I don't really have the time to study them at the moment.I have a string like this:test (22/22/22)I need to capture the test and the date 22/22/22 in an array. the test string could also be a multiple words string:test test(1) tes-t (22/22/22)should capture test test(1) tes-t and 22/22/22I have no idea how to get started on this. I managed to capture the date string with the parentheses by doing:(.*)but that really doesn't get me anywhere.
View 3 RepliesIn the below code if i replace st2 into the pattern of regexp without quotes, it works fine.Now since i get the regular expression from some other file, as it is shown in st2. I want to add that into the regexp pattern. But as in the below code it doesnt work.
<fx:Script>
import mx.controls.Alert
public function onClicking(){
[code].....
I want to know if is possibile through regularexpression, count the numbers contained into a string and add a specified character near it.
For exemple, this is a string: Hello2all821abc13 This string contain 3 numbers: 2, 821 and 13 (note that the numbers contained into 821 and 13 are considered like an unique entity, not signle). I want to add near each of it the "-" symbol. Is it possible?
I rarely use regular expressions and still have a hard time reading/writing them sometimes (getting better, though), but I came across a situation where I needed to split up sentences in a text file and store each sentence as a separate item in an array.
To do this, I have tried to use the split() function by passing it a regex to detect ends of sentences... for most cases, anyway, which includes ., !, or ?, optionally followed by " or )
Here's what I've created:
Code:
sentencesArray = textOriginal_txta.text.split(/(?<=(w[.!?]"?)?))s(?=((?"?[A-Z]))/);
(What this code does is split on condition of a blank space but only where it finds a preceding/prefix that includes end punctuation, plus a lookahead/suffix that contains the beginning of a sentence, such as a capital letter)
The problem is that this doesn't seem to work. It works like a charm when I test it in Expresso free regex writing and testing software), but then when I try to send it to the split, it doesn't split the items. Do I need to do escapes for special characters when sending regex input to a split?
How to create an array from a string. The string will look something like this:
Code:
Main Idea
-Idea 1
--Idea 1 sub point 1
-Idea 2
--Idea 2 sub point 1
---Idea 2 sub point 1 subsub 1
---Idea 2 sub point 1 subsub 2
--Idea 2 sub point 2
-Idea 3
Each "-" indicates a child relationship or 'Sub'. Each child can have any number of children which can have any number of children.
I'm trying to find the number of newlines in a string using the Actionscript 3.0 RegExp engine. Using the string.match function and RegExp(" ","g") does not find the newlines in a string which contains newlines. Is there something I need to add to the pattern or something else that I am missing?
View 1 RepliesI need to write a regex which will match URLs that do not have a specific query string name/value pair anywhere in its URL. All other query string names, and all other query string values with the same name should be matched. Other pages in the same directory (or sub-directories) should not be matched.URL...The query string name and value that I need to exclude from matches is:[code]How can I prevent matches when the string exists anywhere in the pattern?
View 3 RepliesI would like to be able to replace a section of a string with a dash. The section being replaced will be variable.
var str:String = "permanentContainer-temporaryContainer-"
var test:String = "temp";
var pattern:RegExp = /-[(+test+)]+-/i;
trace( str.replace(pattern,"-"));
I would like the result to trace:
permanentContainer--oraryContainer-