Buenas A tod@s en el foro , tengo una duda media boba e interesante he estado viendo varias libreria para manejo de cadenas o mejor dicho un par porque necesito una funcion para cambiar el tamano de una cadena (claro eliminando caracteres ) lamentablemente no encontre ninguna que haga esto eficientemente o que requiera de alguna otra libreria y entonces por esa razon decidi crear una pequena libreria en parte me ha funcionadod correctamente , pero tengo un inconveniente creando una funcion que recorte un mi cadea desde algun punto especifico que pertenezca a ella misma obviamente, quizas se el manejo de memoria. la verdad tengo un par de dias en esto y ya no encuentro como hacer esta funcion , posteare el codigo para recibir su recomendacion para ver si me pueden hechar una mano o algun consejo.
Código (cpp) [Seleccionar]
ini String::CutString(int beg, int end)
{
Dbg(__FUNCTION__, __LINE__, "");
if(this->szChars == NULL)
return 0;
if(this->inlen < end || this->inlen < beg)
return 0;
int inLen = 0;
char *szBeg = NULL;
char *szEnd = NULL;
char *szCharsCopy = NULL;
szBeg = (char *)calloc(inlen, sizeof(char ));
szEnd = (char *)calloc(inlen, sizeof(char ));
szCharsCopy = (char *)calloc(inlen, sizeof(char ));
strncpy( szBeg, &this->szChars[0], beg);
strncpy( szEnd, &this->szChars[end], inlen);
// memcpy( szBeg, &this->szChars[0], beg);
// memcpy( szEnd, &this->szChars[end], inlen);
strncat( szCharsCopy, szBeg , strlen(szBeg));
strncat( szCharsCopy , szEnd, strlen(szEnd));
free (this->szChars);
this->szChars = NULL;
inLen = strlen(szCharsCopy);
this->szChars = (char *)calloc(inLen + 1, sizeof(char ));
strncat( this->szChars , szCharsCopy, inLen );
this->szChars[inLen + 1] = NULL;
if(szBeg)
free(szBeg);
if(szEnd)
free(szEnd);
if(szCharsCopy)
free(szCharsCopy);
if(this->szChars)
return strlen(this->szChars);
else
return 0;
}