SRL Archive - OSR Outdated Tutorials

How to use the "Format" function


Da 0wner

2009-07-05 15:58:36

Format is a function recently added to SCAR in 3.20.

Is is in Delphi.

It is very useful to use.
function Format(s: string; data: array of const): string;
S is the string you wish to format. Data is the data you will add to the result.

They are added wherever a %(INSERTDATATYPEHERE) is added in the string.

d: integer
s: string
g: extended/float
x: hex (19005 to 4A3D)

The above are datatypes.

So
format('I ate %d apples.', [5]);
would return 'I ate 5 apples.'

If you wish to distinguish between different indexes in the array you can do so like:

format('I ate %1:d apples and %0:d pears.', [3, 4]);
would return 'I ate 4 apples and 3 pears.'

You do not need to add the index number if they are in order.

format('I ate %d apples and %d pears.', [4, 3]);
would return 'I ate 4 apples and 3 pears.'

Lmao, I know that tutorial was terrible. I hope you understand…pretty hard to explain. I suck at writing simple tutorials.

Part of it might be that its 5:29AM.

Torrent of Flame

2009-07-05 16:26:37

I think you explained it quite well to be honest dude.

Rich

2009-07-05 16:32:53

From: Torrent of Flame
I think you explained it quite well to be honest dude.


+1. I understand as much as you understand about it right now. Seems like 5:29am is a good time to write tutorials.

Gu3st...

2009-07-05 22:01:41

Yeah, I actually understood it :)
Thank you, I didn't know about that :D

Shuttleu

2009-07-05 22:30:21

didnt know about this and it reminds me of C :p

~shut

Awkwardsaw

2009-07-06 01:28:59

hey, i didnt know either :P

i also under stood it well, mind explaining how it would be used in a script though?

Da 0wner

2009-07-06 01:35:30

Progress reports maybe :D?

Nadeem

2009-07-06 05:07:12

Format is awesome :D

Use it to be neat, and to avoid using IntToStr() and etc… often.



~NS

Harry

2009-07-06 05:20:49

There was no problem with
WriteLn('I ate '+intToStr(apple)+' apples!');
……..

But meh, nice tut :)

ian.

2009-07-06 05:38:09

"It is very useful to use."

>.> lol

Good tut though :) Thank you.

Da 0wner

2009-07-06 05:41:38

Like I said, I was very tired :p.

mrpickle

2009-07-06 07:40:46

I understood that =D. It's to the point with simple examples that helps alot.

p.s. You got my pm?

Da 0wner

2009-07-06 07:45:46

Umm the one with the cup?? If so, yes I have. But I decided to use a different cup :p (check site).