Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string help

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
US
I have a static function that accepts a string(char[]). now is there any way to copy a portion of this string dynamicly into another string? I know I could make both of the arrays the same size and then just copy over what I need, but this seems terribly wasteful. Any help would be greatly appreaciated. MYenigmaSELF
myenigmaself@yahoo.com
 
nevermind, I got it.
I'm actually tokenizing a delimited string pulled from a database. Here's the code if you're interested(it might need some tweaking, not totally finished with it):

Row* Row::processString(CString *string){
Row *row = new Row();

char *str_val=string->GetBuffer(0);

//cout<<str_val;

if(string->GetLength()>0){
char *pointer = str_val;
bool break_flag=false;

for(int i=0;!break_flag;i++){
if(*(pointer+i)=='&quot;'){
int z=0;
i++;
char *add=(char*)(calloc(1,8));
add[0]=NULL;
while(*(pointer+i)!='&quot;'){
z++;
add=(char*)realloc(add,z+1);
add[z-1]=*(pointer+i);
add[z]=NULL;
i++;
}
row->addNode(new CString(add));
cout<<add<<endl;
i++;
if(*(pointer+i)!=','){
break_flag=true;
}
}
else{
break_flag=true;
}
}
}

delete string;

return row;
}

fun!
thanks anyway MYenigmaSELF
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top