Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 581 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 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