| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
#1 |
|
Chief Breaks-many-phones
Join Date: Jun 2007
Location: new york city
Posts: 527
|
Code:
String.prototype._charCount = function(str) {
var cnt = 0, getPos = 0;
while(getPos<this.lastIndexOf(str))
getPos = this.indexOf(str,getPos)+1, cnt++
return cnt;
}
String.prototype._getLine = function(num){
var getPos =0;
var tmpStr;
// if theres no break at the end, add one
if(this.charAt(this.length) != chr(13)) this=this+chr(13);
// run through all line breaks in string
for(var i = 0; i<num-1; i++)
getPos = this.indexOf(chr(13),getPos)+1;
// get the string
tmpStr = this.substr( getPos, this.indexOf(chr(13), getPos+1)-getPos )
return tmpStr
}
String.prototype._getLineByString = function(str){
var getPos =0;
var tmpStr;
var lb = chr(13);
var lines = this._charCount( lb );
// if theres no break at the end, add one
if(this.charAt(this.length) != lb) this=this+lb;
// run through all line breaks in string
for(var i = 0; i<this._charCount( lb ); i++){
tmpStr = this.substr( getPos, this.indexOf(lb, getPos+1)-getPos )
getPos = this.indexOf(lb,getPos)+1;
if(tmpStr.indexOf(str)>-1) return tmpStr;
}
// get the end
return false
}
Usage: Code:
var mystr = "Line 1" + chr(13) + "Line 2" + chr(13) + "Line 3" + chr(13) + "Line 4" + chr(13) + "Line 5"; trace( mystr._getLine(3) ); |
|
|
|
|
|
#2 |
|
it's all about patience
Join Date: Jun 2005
Location: istanbul
Posts: 5,859
|
There are 3 prototypes in there. And what do you mean with optimizing? Making it shorter? Making it/them more processor friendly? Or recreate prototypes that are doing the exact same thing?
|
|
|
|
|
|
|
|
|
#3 |
|
it's all about patience
Join Date: Jun 2005
Location: istanbul
Posts: 5,859
|
ActionScript Code:
Is that what you mean? Last edited by inhan; 07-11-2007 at 04:23 AM.. |
|
|
|
|
|
#4 |
|
;)
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,705
|
or this????
ActionScript Code:
__________________
http://www.pepemagana.com |
|
|
|
|
|
#5 | |
|
Chief Breaks-many-phones
Join Date: Jun 2007
Location: new york city
Posts: 527
|
Quote:
Come up with anything for getLineByString? |
|
|
|
|
|
|
#6 |
|
;)
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,705
|
O_ó
.... what is supposed to be returned on _getLineByString????? false????? ActionScript Code:
__________________
http://www.pepemagana.com |
|
|
|
|
|
#7 |
|
it's all about patience
Join Date: Jun 2005
Location: istanbul
Posts: 5,859
|
I think we're trying to get the line number of a string with that function. Is that right, Matt?
|
|
|
|
|
|
#8 |
|
;)
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,705
|
testing the original function i just get returned false (becase line bellow "// get the end " is returning)
if _getLineByBtring is trying to return the number where the string is, then in the previews function cahnging the returned value will give the line where the string is. ActionScript Code:
__________________
http://www.pepemagana.com |
|
|
|
|
|
#9 |
|
Chief Breaks-many-phones
Join Date: Jun 2007
Location: new york city
Posts: 527
|
No, it returns the actual line its on.. use that function and this here code to see what I mean:
Code:
var str = "This is a" + chr(13) + "new line break" + chr(13) + "quick brown fox" + chr(13) + "lazy dogg";
trace(str._getLineByString("break"));
// returns new line break
|
|
|
|
|
|
#10 |
|
;)
Join Date: Aug 2006
Location: In transit--- Still bored
Posts: 1,705
|
mmmmmmmmmhhhhhhhhhhh.....
:/ so the function i posted return the same!? ActionScript Code:
__________________
http://www.pepemagana.com |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| new string functions! tell me what you need! | colfaxrev | ActionScript 2.0 | 11 | 09-23-2008 10:59 PM |
| Useful Utilities..cookies, key combination,etc | MichaelxxOA | Projectors and CDs | 145 | 08-03-2008 01:45 PM |
| Accessing a string from a variable input text field | matbury | ActionScript 2.0 | 10 | 05-20-2007 12:09 AM |
| Parsing | mtanti | ActionScript 2.0 | 3 | 02-24-2006 04:37 PM |
| 06++ = 7 != 07 | Flash Gordon | Server-Side Scripting | 5 | 01-17-2006 07:27 PM |