Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

Parse a line, when caractere are separated by commas

$
0
0

I want to know if thanks to a function, we can get a caractere at a specific place in a line.

For exemple, I have the line :

a,z,q,1,2,4

I want to get the caractere at the 3rd place, it's 'q'.

I have created this function :

 

char* getValue(char* res, int numArg) {
	int lengthRes;
	char *line = NULL; 	
	int lengthLine; 					
	GetTextBoxLineLength (panelHandle, PANEL_LIGNE, 0, &lengthLine);
		line = malloc(sizeof(char) * (lengthLine +1)); //alloue une partie de la mémoire pour la chaine de caractères
		GetTextBoxLine (panelHandle, PANEL_LIGNE, 0, line);
	//We get what we have in PANEL_LINE
	//We 'parse', then we have "\n" instead of ","
		
	for (int i = 0; i< strlen(line); i++) {
		if(line[i] == ',') {
			line[i]='\n';	
		}
	} //all comma in 'line' are replaced by \n
   	ResetTextBox (panelHandle, PANEL_PARSE, line); //We display 'line' after replaced commas, we will have several lines
	GetTextBoxLineLength (panelHandle, PANEL_PARSE, numArg-1, &lengthRes);
		res = malloc(sizeof(char) * (lengthRes +1)); //alloue une partie de la mémoire pour la chaine de caractères
		GetTextBoxLine (panelHandle, PANEL_PARSE, numArg-1, res);
		//The value of "res" correspond to "numArg"ieme line of 'line', so at "numArg"ieme field
	  return res; //We return "res", that the value we were wanted to have
}

But, when I have many lines to analyse, it take a lot of time, because of th rewritting in the Box etc...

 

Can you help me please ?


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>