gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > getting a portion of a string

#94361 - dh2050 - Mon Jul 24, 2006 4:21 pm

i need to get a portion of a string
like

final string = (current string , get final string start point , length of final string)

something like the 'mid' function for vb

any idea how to do it?

#94362 - Primetime00 - Mon Jul 24, 2006 4:31 pm

Code:
strncpy(final, &current[start], length);

#101318 - dh2050 - Mon Sep 04, 2006 12:01 pm

its seems that memcpy and strncpy doesnt work on the ds...
any other alternative?

#101319 - dh2050 - Mon Sep 04, 2006 12:03 pm

sry but its for data type... not string sry for the mistake

#101322 - Lick - Mon Sep 04, 2006 12:20 pm

Code:
char portion[128] = {0}; // make sure it's big enough
char original[] = "1234567890HAHAHAHAHHAHA"; // hehe..
memcpy(portion, &original[10], 4);

// portion should now contain "HAHA"


This is just the same as Primetime00's code, but a bit lengthier to explain how it works.
Memcpy and Strncpy DO work on the DS.

-edit-
For data types? simply do this:
Code:
memcpy(dest, &src[sizeof(DataType) * 4], sizeof(DataType));

_________________
http://licklick.wordpress.com

#101513 - dh2050 - Wed Sep 06, 2006 5:13 am

thks guys
it works fine now

i found the main problem
but it wasnt the strncpy problem