Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,238 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Snippets: string functions (str_sub,str_pad...) #57580
10/13/05 20:47
10/13/05 20:47
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Some string functions for basic string operations (not included in C-script, converted by me from other language)
Code:

string TempStringPad; //Temp string for padding
string* TempStringPtr; //Temp string pointer for 'type casting'
string* TempCharPtr; //Temp string pointer for 'type casting'

function str_sub(s,pos,len){ //returns ptr to substring of string s from pos to pos+len
TempStringPtr=s; //this func isn't modifying original string
str_cpy(TempStringPad, TempStringPtr);
if (pos > str_len(TempStringPad)) {
pos=str_len(TempStringPad);
}
if ((str_len(TempStringPad)-len-pos)<0) {
len=str_len(TempStringPad)-pos;
}
str_clip(TempStringPad,pos);
str_trunc(TempStringPad,str_len(TempStringPad)-len);
TempStringPtr=TempStringPad;
return(TempStringPtr);
}
function str_padl(Src, C, Lg){ //pad string src with cahr C from left
TempStringPtr = Src; //this func is modifying original string
TempCharPtr = C;
str_cpy(TempStringPad, "");
while ((str_len(TempStringPtr)+str_len(TempStringPad)) < Lg) {
str_cat(TempStringPad, TempCharPtr);
}
str_cat(TempStringPad, TempStringPtr);
str_cpy(TempStringPtr, TempStringPad);
return(TempStringPtr);
}
function str_padr(Src, C, Lg){ //pad string src with char C from right
TempStringPtr = Src; //this func is modifying original string
TempCharPtr = C;
while (str_len(TempStringPtr) < Lg) {
str_cat(TempStringPtr, TempCharPtr);
}
return(TempStringPtr);
}
function str_padc(Src, C, Lg){ //pad string src with char C from both sides
TempStringPtr = Src; //this func is modifying original string
TempCharPtr = C;
while str_len(TempStringPtr) < Lg {
str_cat(TempStringPtr, TempCharPtr);
if str_len(TempStringPtr) < Lg {
str_cpy(TempStringPad, TempCharPtr);
str_cat(TempStringPad, TempStringPtr);
str_cpy(TempStringPtr, TempStringPad);
}
}
return(TempStringPtr);
}


Usage example:
Code:

string RString;
...
str_cpy(RString,"01234567890123456789");
str_cpy(RString,str_sub(RString, 10, 3)); // RString="012"
...
str_cpy(RString,"01234567890123456789");
str_cpy(RString,str_sub(RString, 21, 20)); // RString=""
...
str_cpy(RString,"0123456789\n");
str_padr(RString,"_",20); //don't try to use "___" or "" in second parameter !!!
str_cat(RString,"0"); //second line has 0 aligned with "_" to 9 position of first line
...
str_cpy(RString,"0\n");
str_padl(RString,"_",11); //don't try to use "___" or "" in second parameter !!!
str_cat(RString,"0123456789"); //first line has 0 aligned with "_" to 9 position of second line
...
str_cpy(RString,"0\n");
str_padc(RString, "_",20); //don't try to use "___" or "" in second parameter !!!
str_cat(RString,"0"); //two lines has 0s aligned at right with "_"
...



Re: Snippets: string functions (str_sub,str_pad... [Re: Lion_Ts] #57581
10/13/05 21:10
10/13/05 21:10
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
ok. i a few days, i´ve planed, i will release some scripts. i don´t release many scripts. but then...

some of your commands i´ve progged too. :-/
but i´ve progged more than you

Re: Snippets: string functions (str_sub,str_pad... [Re: Tempelbauer] #57582
10/13/05 22:36
10/13/05 22:36
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Good idea. For all.
P.S.
(big secret)I programmed much more stuff , but unfortunally, not with C-script
and now it's a big pain in ..., try to recode some good pieces with C-script restrictions...



Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1