Closed Thread Icon

Preserved Topic: split() using more than one argument? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18444" title="Pages that link to Preserved Topic: split() using more than one argument? (Page 1 of 1)" rel="nofollow" >Preserved Topic: split() using more than one argument? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-29-2002 00:51

Greets!

Let's say I have this function:

function maxPrettyText(text) {
textParts = text.split("_");
output = "";
for (j = 0; j <= textParts.length-1; j++) {
output = output + maxCaps(textParts[j]);
if (j != textParts.length-1) { output = output + " "; }
}
return output;
}


That basically replaces all of the "_" with " ".

What I'd like to do is also do the same thing with "%20" - replace it with " ". So the question is, can I use the same split statement to handle both, or do I need to take the array from the first one and split that?


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-29-2002 01:21

The split function can actually take a regular expression. So you can use this to do both at once:

text.split(/_

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-29-2002 05:57

Okay. The first example you gave works great. The others are going to need some tweaking because they need to call other functions like maxCaps()....

I'll noodle with that later. Thanks for the explanations - they actually make sense!

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-29-2002 05:59

Oops, didn't see maxCaps() =)

Depending on what that function does, you might be able to just run it on the finished string. I'm not sure.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-29-2002 06:57

What maxCaps does is take the finished string, and capitalize each word, while make the rest of the word lower case.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-29-2002 11:27

Do I see part of my "bread crumbs" JavaScript here, heh...

Anyway, as far as optimization is concerned, maxCaps function must be called for each word (contained in textParts array), so you still need one for loop, and since there's already one for loop, I didn't want to use join() function afterwards, because I can do both things in the same loop (call maxCaps() function and assemble complete string).

Now, since JavaScript has very good support for regular expressions, I can use one regex and one small function to do the same thing, but I don't have time to write that code...


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-29-2002 18:38
quote:
Do I see part of my "bread crumbs" JavaScript here, heh...



Yes you do, Max! And a damned nice script it is!

Actually, I'm just adding a couple of more functions to tweak it a little. The %20 issue is just for dealing with the spaces when using it locally on a hard drive. Not a real big issue - it just kinda bugs me. I'm gonna do a couple more things to it and then use it on a new site we're working on.

I love this script!

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-30-2002 07:03

I'm curious. What other functions / features you want to add to it?


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-30-2002 18:28

Actually, the only other thing I need to add is a function to correct an issue when using it locally (other than the %20 issue I mentioned above). When using it locally, the path is not correct.

The crumbs end up with several instances of file:///c:/file:///c:/, thus throwing things off. Not a big deal, but I'd like to resolve that.....

The code as I'm using it now is:

<!-- ;

////////////////////////////////////////////////////////////////////////////////
// MAX's Bread Crumbs
// Written by mr.maX, http://www.max.co.yu/
// Enhanced by Pugzly, http://www.runningwolf.com/
// Configuration ///////////////////////////////////////////////////////////////

// Number of levels to show (excluding document title)
// If you specify negative number it will start counting from the end,
// otherwise it will start counting from the beginning...
maxLevels = 12;
// Separator
maxSeparator = " <b>»</b> ";
// Link last part?
maxLPLink = true;
// Show 'HOME' link as the first part?
maxShowHome = true;
// 'HOME' link title
maxHomeTitle = "Home";
// Show document title as the last part?
maxShowTitle = true;

// Helper functions ////////////////////////////////////////////////////////////

// Capitalize text
function maxCaps(text) {
return text.charAt(0).toUpperCase() + text.substring(1, text.length).toLowerCase();
}

// Make text pretty
function maxPrettyText(text) {
textParts = text.split(/_

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-30-2002 18:50

Unfortunately, there is no way for script to know what is the web site's root folder locally (i.e. you can place it several folders deeper from root, but it can't find out what is root / starting folder)...


« BackwardsOnwards »

Show Forum Drop Down Menu