tags:

views:

30

answers:

1

hello,

i ve a string , for example:

NSString *str = @"12,20,40,320,480"

This str has to be given as buffer value,

UInt8 *buffer;

Now how to give the str as buffer value? The value of str string keeps changing , and hence buffer has to dynamically take the value as str everytime. plz help me how to achieve this.

Thank You.

A: 

Your question is pretty unclear but if you want to create an array of UInt8s from a NSString that stores a comma separated list of numbers you have to parse the string to individual numbers and then convert each number's string representation to a UInt8 representation

Something like but with extra code for validating the NSString input:

NSString *str = @"12,20,40,320,480";

NSArray * str_a = [str componentsSeparatedByString:@","];
UInt8 * buf = malloc(sizeof(UInt8) * [str_a count]);

int i;
for(i=0;i<[str_a count];i++)
    buf[i] = atoi([[str_a objectAtIndex:i] cStringUsingEncoding:NSASCIIStringEncoding]);

// do something with the buffer
somefunction(buf);

// free the buffer
free(buf);
diciu