Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-11-2006, 10:34 PM   #1
colfaxrev
bit chez fr.digital house
 
colfaxrev's Avatar
 
Join Date: Mar 2006
Location: Los Angeles
Posts: 688
Default new string functions! tell me what you need!

I am writing an extention to the String class, which includes all the methods of the original String class.

ex. charAt() charCodeAt() fromCharCode(), slice(), etc...

i am adding more methods to make manipulating strings in flash a breeze.

here are the methods i have working now.

charOccurCount(ch);
returns a count of occurances of a specified character.
note: if your string is longer than 1 character this will return -1;

convert_stringToHex()
returns a hex encoded string.

genUniqSuffix(prefix)
returns a guaranteed uniq suffix to fix your cache problems.
prefix defaults to "?uniq=" so you dont need to include the argument.

replaceWithArray(ary, rs)
returns a string after replacing a specified string with elements in an array
ex.

ActionScript Code:
var s:XString = new XString("Michael is .::. because he never saw a .::. before .::."); trace(s.replaceWithArray(new Array("amazed", "dog", "today"), ".::."));

traces this...

Michael is amazed because he never saw a dog before today

shiftCharCode(n)
returns string;
n is a number that will be added to the charCode of each character.

ex. if your string is "abcd" and you use shiftCharCode(1) then your returned string will be "bcde"

trimEnds()
returns string;
this cuts away all white space before and after you string.
ex. your string is " trim me ", then your return string will be "trim me"

trimL()
returns string;
trims all white space before string

trimR()
returns string;
trims all white space after string

validateEmail()
returns Boolean;
first runs trimEnds() and then checks string for certain requirements like having 1 '@' char, and having a domain name of at least 3 chars, and a suffix of at least 2 chars, and that the first char in the string is not the '@'

ex. [email protected] will return true
@abc.tv will return false
[email protected] will return false
[email protected] will return false;

[email protected] is supported, will return true

I KNOW there is more needed, if you have any needs for parsing strings in a certain way then let me know, i want to build this thing up.
colfaxrev is offline   Reply With Quote
Old 03-11-2006, 10:39 PM   #2
MichaelxxOA
Flash Sucks
 
MichaelxxOA's Avatar
 
Join Date: Mar 2005
Location: Victorville, Ca
Posts: 2,228
Send a message via AIM to MichaelxxOA Send a message via MSN to MichaelxxOA Send a message via Yahoo to MichaelxxOA Send a message via Skype™ to MichaelxxOA
Default

I think you have a great thing going, one thing I would have to say though is that validateEmail() is not a method that should belong in this class. It does not have to do with manipulating the string... it's a method that belongs in a StringValidation class or something. Take Care.


Ps. There is also a method called insertion that I wrote for my StringUtility class, I would suggesting throwing that in there as well. Take Care.

_Michael
MichaelxxOA is offline   Reply With Quote
Old 03-11-2006, 10:53 PM   #3
colfaxrev
bit chez fr.digital house
 
colfaxrev's Avatar
 
Join Date: Mar 2006
Location: Los Angeles
Posts: 688
Default hey

thanks for the reply

yeah im probably going to write a separate class for validation.

but i did take your advice and add this method

insertStrAt(str, n)
str is what your sticking in the string, and n is where
colfaxrev is offline   Reply With Quote
Old 03-11-2006, 11:06 PM   #4
MichaelxxOA
Flash Sucks
 
MichaelxxOA's Avatar
 
Join Date: Mar 2005
Location: Victorville, Ca
Posts: 2,228
Send a message via AIM to MichaelxxOA Send a message via MSN to MichaelxxOA Send a message via Yahoo to MichaelxxOA Send a message via Skype™ to MichaelxxOA
Default

That's cool to, but not what I was refering to . In my string utility class I have a method called insertion(). This is how it is used...

ActionScript Code:
var s = StringUtility.insertion("Link to {1}: <a href='{0}'>{1}</a>", "http://www.createage.com", "Michael's Site"); // traces... Link to Michael's Site; <a href='http://www.createage.com'>Michael's Site</a> trace(s);

This is an extremely useful thing to do with your string. Take Care.

_Michael
MichaelxxOA is offline   Reply With Quote
Old 10-19-2006, 09:23 AM   #5
Morg
1st party software!
 
Morg's Avatar
 
Join Date: Nov 2003
Location: South Africa
Posts: 916
Default

Hey man!

Did you ever manage to finish this? Is it available for download?

Pls lemme know - looks like a nifty utility!
Morg is offline   Reply With Quote
Old 10-19-2006, 04:33 PM   #6
colfaxrev
bit chez fr.digital house
 
colfaxrev's Avatar
 
Join Date: Mar 2006
Location: Los Angeles
Posts: 688
Default !!!

here!!! I've attached it.

I don't have the documentation on me here at work. I have it at home though. I will try to remember to post that up at lunch or after work today.

but to get you started, just put that XString.as file in the same directory as your FLA file.

Here's some examples to get you started

Code:
var Xstr:XString = new XString(); //you can put a string inside as an argument I'm sure...
Xstr.set("testing");
trace(Xstr);
trace(Xstr.generateAlphaNumKey(30));
Xstr.set("148674.347748");
trace(Xstr.moneyFormat("$", true));
Xstr.set("     white space on left and right    ");
trace("["+Xstr.trimEnds()+"]");
trace(Xstr.validateEmail("[email protected]"));
trace(Xstr.validateEmail("[email protected]"));
trace(Xstr.validateEmail("[email protected]"));
trace(Xstr.validateEmail("bryan!hotmail.com"));
trace("------\nUse this one to stop caching of external files.");
//It adds the date, down to the millisecond and adds a random number to just be sure!
trace("mydata.xml"+Xstr.genUniqSuffix());
trace(Xstr.reverseString("racecar")); //haha jk, thats the same either way...
trace(Xstr.reverseString("abcdefghijklmnopqrstuvwxyz"));//but that one will show you what it does
Attached Files
File Type: zip XString.zip (3.9 KB, 310 views)
__________________
Music is life
colfaxrev is offline   Reply With Quote
Old 10-20-2006, 08:11 AM   #7
Morg
1st party software!
 
Morg's Avatar
 
Join Date: Nov 2003
Location: South Africa
Posts: 916
Default

You rock! Thanks matey!
Morg is offline   Reply With Quote
Old 10-20-2006, 09:18 AM   #8
jsebrech
Joeri Sebrechts
 
Join Date: Apr 2005
Location: Antwerp, Belgium
Posts: 1,465
Default

Thanks for sharing. If you're open to improvements, I think you could make this stuff a lot faster by using split and join.

A faster replace is "string.split('searchforthis').join('replacewithth is')". A faster charOccurCount is "string.split(chartocheck).length - 1". What you should avoid at all costs is having to loop over a string one character at a time, because flash is dead slow at that.
jsebrech is offline   Reply With Quote
Old 10-20-2006, 09:27 AM   #9
blockage
Senior Member
 
blockage's Avatar
 
Join Date: Jan 2005
Posts: 476
Default

I would also be more useful as util class - that way I wouldn't need to re-write any exsiting code to use it. Also, I haven't tested this but native string operations are probably faster than yours.
__________________
Who cares what it does - I just wanna write CODE!
blockage is offline   Reply With Quote
Old 10-20-2006, 04:05 PM   #10
colfaxrev
bit chez fr.digital house
 
colfaxrev's Avatar
 
Join Date: Mar 2006
Location: Los Angeles
Posts: 688
Default

its fast enough for me right now. I mean it's not like I'm doing crazy string manipulation in flash using like 5000 characters in a string. I use PHP for stuff like that. I'm glad that someone found it useful though. When I find time I might change the stuff to split, join. but for now its totally fine.
__________________
Music is life
colfaxrev is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Useful Utilities..cookies, key combination,etc MichaelxxOA Projectors and CDs 147 11-08-2013 11:28 AM
Parsing mtanti ActionScript 2.0 4 03-11-2010 11:43 PM
06++ = 7 != 07 Flash Gordon Server-Side Scripting 5 01-17-2006 06:27 PM
Some basic questions on functions and vars etc. mikebr Simple Stuff (Newbies) 2 12-12-2004 08:15 AM
call a parent function when only having a string of that function's name dejavuuuuu ActionScript 1.0 (and below) 6 09-09-2002 03:08 PM


All times are GMT. The time now is 12:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.