|
3 registered members (AndrewAMD, Grant, Neb),
908
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: get a single character from string
[Re: Hummel]
#261249
04/16/09 14:38
04/16/09 14:38
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
no, but you could do this
str_cpy(str1, str2); str_clip(str1, 5); (str1.chars)[1] = 0;
should do it.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: get a single character from string
[Re: EvilSOB]
#261268
04/16/09 15:59
04/16/09 15:59
|
Joined: Mar 2006
Posts: 2,252
Hummel
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,252
|
ok,it works - thx! void str_get_chars(STRING* str1,STRING* str2,int start_num,int count) { str_cpy(str1, str2); str_clip(str1, start_num-1); (str1.chars)[count] = 0; } str_get_chars(str,"A new function for Lite-C",7,8);//str contains "function" have a nice day! 
|
|
|
Re: get a single character from string
[Re: Hummel]
#261283
04/16/09 16:40
04/16/09 16:40
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
very good idea  (do not react on sarcasmn  ) Okay but i also want to explain.. Imagine the following: You have a string with the length of 10.000 characters. You want to get the second character. 1) str_cpy is SLOW in this case 2) you set the 3 character to zero in this case, and by that signalize that the string ends here. ==> 9.997 characters of endless memory waste  at least take str_trunc instead of setting a char to zero.
|
|
|
Re: get a single character from string
[Re: TechMuc]
#261334
04/16/09 22:51
04/16/09 22:51
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
void str_get_chars(STRING* str1,STRING* str2,int start_num,int count)
{
str_cpy(str1, str2);
str_clip(str1, start_num-1);
(str1.chars)[count] = 0;
}
str_get_chars(str,"A new function for Lite-C",7,8);//str contains "function"
very usefull snippet, btw  well, i may write it somewhere, not to lose
|
|
|
Re: get a single character from string
[Re: VeT]
#261358
04/17/09 07:07
04/17/09 07:07
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
A variation of Hummels variation of my code - for TechMuc (slower in number of instructions, but more efficient in memory used.
//(this is untested)
void str_get_chars(STRING* dest,STRING* source,int start_num,int count)
{
str_cpy(dest, "");
int c; for(c=0; c<count; c++)
{
str_cat(dest, " ");
(dest.chars)[c] = (source.chars)[start_num + c];
}
}This more your flavour TechMuc?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|