Closed Thread Icon

Preserved Topic: format('hello %s, welcome to the asylum!', 'newuser'); Pages that link to <a href="https://ozoneasylum.com/backlink?for=18112" title="Pages that link to Preserved Topic: format(&amp;#039;hello %s, welcome to the asylum!&amp;#039;, &amp;#039;newuser&amp;#039;);" rel="nofollow" >Preserved Topic: format(&#039;hello %s, welcome to the asylum!&#039;, &#039;newuser&#039;);\

 
Author Thread
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-04-2001 09:10

Hello....

anyone did a simple (doesn't have to be very advanced) Format() like function for JS ?

if so can you plz give me some links?

3rdperson
Paranoid (IV) Inmate

From: your subconscious. (scared yet?)
Insane since: May 2001

posted posted 09-04-2001 11:33

threep scratches his head, and asks:
"what exactly do you want to do? format the text? how?
if you want to change the format of the text (all caps, all lowercase, capitalised 1st letter) css can be han-dee.
other than that, i'm not too sure what you want done..."


lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-04-2001 12:59

no no threep,

the Format() that i'm talking about is like the sprintf() in C language.

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 09-04-2001 18:35

Why not use Javascript's native methods for that? Is there some reason you need to emulate the printf function?

document.write("Hello "+name+", welcome to the Asylum.")



lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-05-2001 09:01

Yes Bugimus....It's I find better and makes your code more readable if you can just use something like sprintf()

so there is nothing like sprintf() for js?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-05-2001 14:49

Nope. You'll get used to string concatenation soon enough though. =)

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 09-05-2001 20:09

I double checked and I can't find anything for javascript like you ask. It's funny because if you think about it, printf, isn't part of the C language either. It is a function that someone wrote using C. So if you really wanted printf in javascript, you or someone else would have to write it. Don't worry, Slime's quite right about getting used to it.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-06-2001 12:28

i hate concating lots of strings...it makes my code unreadable....
anyway, i coded this simple routine that someone might find it useful,

code:
<body onmousemove="status = jsprintf('current x:%s, y:%s', event.clientX, event.clientY)">
<script language="JavaScript">
<!--
function jsprintf()
{
// v0.0.1
str = arguments[0]; j = 1;
while ( (idx = str.indexOf("%s")) != -1)
str = str.substr(0, idx) + arguments[j++] + str.substr(idx+2);
return str;
}
//-->
</script>
</body>



« BackwardsOnwards »

Show Forum Drop Down Menu