Get Section Of A String


	some_other_string = my_string.substr(8, string::npos);    //Copy from character 8 to the end

Get String After String


	my_string = my_string.substr((my_string.find("inet ") + 5), string::npos);

Get String Before Character


	my_string = my_string.substr(0, my_string.find('/'));		//Will return existing string if character not found

Convert ASCII string of hex values to binary array example code


//----- CONVERT ASCII STRING TO BINAY ARRAY -----
string my_source_string = "> 04 3E 2B 02 01 00 00 B7 82 25 3F 23 AC 1F 02 01 06 03 03 F1 FF 17 16 A8 89 7C 96 39 3C 4A A0 B3 EF 43 0D A8 21 F3 54 00 00 00 00 C5 64";
const int MY_ARRAY_LENGTH = 44;
char *p_buffer;
char high_char;
char low_char;
BYTE my_binary_array[MY_ARRAY_LENGTH];
int count;
	
	count = 0;
	if (my_source_string[0] != '>')
		return;
	p_buffer = (char*)hcidump_event.c_str();
	p_buffer++;
	while (1)
	{
		p_buffer++;
		
		if (*p_buffer == 0)
			return;				//Wasn't long enough so can't be iBeacon

		if (*p_buffer == ' ')
			continue;
		
		if (*p_buffer == '\n')
			continue;
	
		//We have next 2 digit value
		high_char = *p_buffer++;
		low_char = *p_buffer;
		if (
		(high_char < '0') || (high_char > '9') &&
		(high_char < 'A') || (high_char > 'F') &&
		(high_char < 'a') || (high_char > 'f')
		)
		{
			return;
		}
		
		if (
		(low_char < '0') || (low_char > '9') &&
		(low_char < 'A') || (low_char > 'F') &&
		(low_char < 'a') || (low_char > 'f')
		)
		{
			return;
		}
		my_binary_array[count++] = convert_ascii_hex_to_byte(high_char, low_char);
		
		if (count >= MY_ARRAY_LENGTH)
			break;			//We have all the values we want
	} //while (1)
//We have our array of values

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *