Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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 | 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