View Full Version : string manipulations
mediachickie
September 16th, 2002, 11:22 PM
I have a string manipulation questions:
Lets say I have a string that is a Path ( c:/thisdoc/thisdir/thisfile)-
and I want to only get certain info from the string - such as "thisfile" - do I use split or splice? Any suggestions or tutorials that someone could point me to would be much appreciated.
thanks!
lostinbeta
September 17th, 2002, 12:49 AM
split is for arrays
splice is for string manipulation
I am not sure how to use them, I only know that "splice" is the one you are looking for out of those 2.
pom
September 17th, 2002, 01:13 AM
You have to use split:
//you have a string
myStr="c:/thisdoc/thisdir/thisfile";
//a is an array containing the elements separated by /
a=myStr.split("/");
//file is the last element of that array
file=a[a.length-1];
trace (file);pom :asian:
lostinbeta
September 17th, 2002, 01:16 AM
Hmm, I could have sworn splice was for strings and split was for arrays. Maybe I am confusing myself again.............
pom
September 17th, 2002, 01:37 AM
well, strings and arrays aer a bit alike... :)
lostinbeta
September 17th, 2002, 01:41 AM
Good to know.....good to know. I really need to read up more on both. Actually, I really need to start buying books for what I am learning...haha.
eyezberg
September 17th, 2002, 03:05 AM
you could also use "lastIndexof" to get the last dash, and then retrieve the remaining substring based on that value..
How about a string manipulating contest?
And strings are not like arrays..are they..? lol The more i think about theur differences, the less there are..well anyway, they're both usefull, so go get that (Moock) book!
upuaut
September 17th, 2002, 03:08 AM
.. ahh. .a string manipulation contest.. I might actually have some luck with that one. Good idea Eyez
Bezzer
September 17th, 2002, 06:00 AM
i think i need to get a book too....it would be good to actualy know what im doing for a change.. :)hehe
lostinbeta
September 17th, 2002, 12:02 PM
Ok, I am screwed enough in the AS contest, please don't start a string manipulation contest......haha. Just kidding:)
pom
September 17th, 2002, 03:43 PM
Hmm... Strings are a bit like arrays, Eyez. Just a bit, but they are :) I know C. Moock would disagree with me on that one, but hey...
pom :asian:
lostinbeta
September 17th, 2002, 05:08 PM
Sounds confusing... I am going to jump out of this thread before I hang myself with a String from an Array:P
upuaut
September 18th, 2002, 02:23 AM
well lost.. really string manipulation is not that tough. If I know you, you'd pick up most of the principals pretty quickly.
You'll need to know the basics of it to work with XML docs anyway. Many of the methods used on strings are very similar to methods used on XML nodes and Array for that matter. (which is why Pom says they are similar to each other.)
lostinbeta
September 18th, 2002, 02:26 AM
Do you know any good tutorials on strings?
I have good info on Arrays, I just need to find something to teach me strings.
http://www.flashmagazine.com/html/480.htm
http://www.flashmagazine.com/html/509.htm
There are the links on info I have on Arrays, I think it is pretty informative. Figured if anyone else read this and wanted to learn, they could use those links.
upuaut
September 18th, 2002, 02:33 AM
Well.. most of it's pretty straight forward.
name the string and then call a string method. ie
someSting.length();
gives you the length of the value of the string.
There are, I guess, quite a few methods that you can use on strings which would be hard to post all of here. If I can find a good tutorial, I'll pass it on.. otherwise it looks like that will probebly be my next tutorial after the xml one. both the XML tutorial, and a 'string' tutorial will compliment each other anyway.. so it certainly wont hurt to be creating both close together.
lostinbeta
September 18th, 2002, 02:35 AM
Awesome, thanks david.
eyezberg
September 18th, 2002, 02:54 AM
Working on one too..sometimes, when i get time..will take some time..ti-i-i-ime is on my side..
Ryall
September 18th, 2002, 02:17 PM
...yyyes it iss. :nerd:
pom
September 18th, 2002, 06:31 PM
Hey Eyez, are you working on an XML tute or a String methods tute (for Lost, the best ressource I know: the AS dictionary)?
pom :asian:
Bezzer
September 18th, 2002, 07:31 PM
arrays arn't like strings....strings is just a string of caracters all joined to gether, where as an array is an ordered set of alike things like a set of numbers, letters, or values...arrays are easier to refer to a certian entry as well.....you just use the myArray[i], with strings you would have to chop and change them to get the right thing...
I meant to reply to this yesterday...but my computer was anoying me...hehe oh well :)
lostinbeta
September 18th, 2002, 07:50 PM
In a previous post to this thread by david....
Many of the methods used on strings are very similar to methods used on XML nodes and Array for that matter. (which is why Pom says they are similar to each other.)
Bezzer
September 18th, 2002, 07:54 PM
fine :P hehe
lostinbeta
September 18th, 2002, 08:07 PM
Seems to be a big debate. I already stated I didn't know enough about either to boast my opinion on likenesses.
mediachickie
September 18th, 2002, 08:09 PM
okay - so here is another one
what if a string is like this:
path\subdir\lalal\file
does the delimiter become ("\\")?
I tried doing a prototype for it - but its chopping off a letter of some the string
String.prototype.splitIt=function(delimiter1){
a=this.split(delimiter1);
b=a[a.length-1];
return b;
}
anyone see what is wrong- it should be obvious - but I must be blind!
thanks for all the great posts by the way!
mc
Mr. Twinkles
September 18th, 2002, 11:55 PM
i'm gonna have to agree that strings are like arrays, in that they are an array of characters, just with a different syntax than an actual array. see, you can pull just one character from a string, just like you can pull one position and object from an array
upuaut
September 19th, 2002, 12:59 AM
It's not really true. Arrays CAN be like strings and or like XML node trees, but both node trees and array can be so much more. A string can only be a string. The imporant part to a programer is that strings, array and xml nodes can all be manipulated by SOME of the same methods. (at least they seem the same when writing them.)
ie.
myXml.length();
someVariable.length();
myArray.lenth();
these all work the same way.. using the first object in the hierarchy as the number 0 item and counting up from there. The difference is that you can't use a 'split();' method on an XML tree. Nor can you use 'childNode' on anything but an XML tree. So the answer is that they are not the same thing.. they just share some common methods.
upuaut
September 19th, 2002, 01:01 AM
I guess that's just a repeat of what I said before.. but I guess I thought that I was being a little more clear in this post. ;)
sbeener
September 19th, 2002, 01:19 AM
mediachick,
yes "\\" is correct because "\" will escape the second quote. in this case you need to escape the backslash, thus "\\".
you get strange results because \f is a special character. solution is to (again) escape the backslash:
str = 'path\subdir\lalal\\file';
incidentally, no need to split the string into an array with that function, lastIndexOf will help you out:
String.prototype.splitIt=function(d){
return(this.substr(this.lastIndexOf(d)));
}
and in the string is like an array debate, i'm firmly in the "not the same thing" camp.
pom
September 19th, 2002, 02:50 AM
Originally posted by sbeener
and in the string is like an array debate, i'm firmly in the "not the same thing" camp. Ouuhh... That one hurt... Let me explain then: I said that I find arrays a bit similar to strings sometimes because of the .length thing, and because elements of a String can be accessed quite similarly to Arrays elements (in very simple cases). Of course I never said they were the same, but the way I see it, you could use Arrays instead of Strings in most cases (and in C, C++ and Java, Strings are in fact arrays of char if I'm ot mistaken so I don't how Flash works, but it must be similar).
pom :P
upuaut
September 19th, 2002, 02:53 AM
roflmao.. poor Pom..
I knew what you meant anyway... don't listen to us peanut gallery types. We love you Pom, and you go on thinking that strings and array are whatever they need to be to you, to let you grasp them. I often use associations for things to help me remember how to use them. Rarely do they make sense to anyone other than myself.
lostinbeta
September 19th, 2002, 02:57 AM
Haha, word association is about 95% of the method I have to use to memorize things. No one can understand it, but it works good for me. You could say the word apple and I will remember I have to return a rented movie, I will remember that because there was an apple in the movie or something. Very odd, I don't even understand it, my brain just works it out on its own.
This thread has been very educational to me. I stood back and learned. I still need to learn more of the basics though. Whenever I seem to run a search for tutorials on strings I get all these entries for learning RegEXP for MX. Is this what I need to know?
pom
September 19th, 2002, 03:06 AM
Thanks Upu :)
And Lost, RegEXP are useful, so you should definitely learn that, but if you want to learn the Strings methods, open the AS dictionary and just try them...
pom :asian:
lostinbeta
September 19th, 2002, 03:13 AM
Sounds fun fun fun, I guess I will do that friday or saturday. I won't be home tomorrow so I can't try it then.
Time to find that RegEXP site again. It looked very useful, it gave a list of things and described what each did.
upuaut
September 19th, 2002, 07:03 AM
can you guys explain a little bit of what 'RegEXP' is?.. and is it something that's new with MX, because I've never heard of it.
lostinbeta
September 19th, 2002, 11:54 AM
http://www.jurjans.lv/flash/RegExp.html
There is the link I found on it. It may be useful. It says it is for Flash 5 and MX david.
sbeener
September 19th, 2002, 01:31 PM
RegExp = regular expressions.
very powerful method of pattern matching in strings.
ily - no hard feelings! consider ... you can have an array of strings, but can you have an string of arrays?
pom
September 19th, 2002, 01:34 PM
Ahaha! I was waiting for your answer Supra :P
I agree with you, their are not the same, but what's a String? An array of char. So let's settle with this: Strings are a very particular kind of arrays... Or do you disagree?
pom :)
eyezberg
September 19th, 2002, 04:44 PM
Ah ha: Supra, this:
'you can have an array of strings, but can you have an string of arrays?'
is EXACTLY the words i was thinking when i started posting that strings are not like arrays!
And then i thought
var string = "[1,2,3], [4,5,6],[7,8,9]" and so on....
Basically, you can put whatever in a string, cantcha?
pom
September 19th, 2002, 04:55 PM
But you don't really have an array in a string in that case... You'd have to parse for half an hour before you can reconstruct the array :)
eyezberg
September 19th, 2002, 05:27 PM
Hey, YOU were saying they're the same, and now you deny the obvious?! lol
It's not one array, it's 3 of em in that string, so you'd just split at "," and then array1 = resultOfSplit[0], array2 = resultOfSplit[1} etc..
pom
September 19th, 2002, 05:31 PM
You split at ",", hue? And how many "," do you have, Eyez? :P
eyezberg
September 19th, 2002, 05:38 PM
Fais ch.... LOL ta gueule! :P (je rigole...)
ok, replace the ones between the [] by sthing else to split..
pom
September 19th, 2002, 05:56 PM
:P
sbeener
September 19th, 2002, 06:24 PM
Originally posted by ilyaslamasse
"Strings are a very particular kind of arrays... Or do you disagree?"
i disagree. a string is a flat, literal datatype. an array is more like a reference to information. it can contain strings, objects, more arrays, booleans, etc. just about anything, and just about any number of anything.
ever loaded a bunch of movie references into an array to work with all of them at once? try that with a string. sure, you could have them comma delimited and then split them into an array and then evaluate th... hold on, did you just change it into an array? see what i mean?
it's not that they have *no* similarities, it's just that they have so many more differences.
pom
September 20th, 2002, 12:30 AM
Hmm... I'm just arguing now because French people have to argue to the death...even if they're wrong (I'm not saying it is the case here :P)
OK, no, forget it. I'm convinced :) Even though you'll agree that Arrays and Strings are a bit alike :P Overwhelming Frenchood mode engaged
pom :asian:
eyezberg
September 20th, 2002, 03:49 AM
ilyaslamasse.removeMovieClip(now);
discussion.stop(now);
var useless = true;
if (useless == true){
var funny = true also;
}else{
lol;
}
I like this thread, let's put it in an array!
Then we split it up between all posters,
parse it, send it to an XML socket and
unescape everything before going nuts..
:P :) =)
upuaut
September 20th, 2002, 03:52 AM
nice code there eyez.. I almost wet myself. (no not really.. it's just an expression. been using roflmao too many times lately)
pom
September 20th, 2002, 07:50 AM
Hey you can't remove me like that! Read the AS dictionary more carefully
Ilyaslamasse.overWhelmingFrenchhood
Syntax
myIlyaslamasse.overWhelmingFrenchhood=true;
Arguments
none
Description
Property; turns your Ilyaslamasse object into a super object, impossible to delete, and subsequently never wrong about anything.
Player
Flash 5 or later.
Example
The following example creates an Ilyaslamasse and use the overWhelmingFrenchhood property.
myI=new Ilyaslamasse();
myS=new Supra();
myE=new EyezBerg();
myI.overWhelmingFrenchhood=true;
myE.deleteMovieClip(myI);
// returns false
myS.isWrong(myI);
//returns true
pom :asian:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.