-
Notifications
You must be signed in to change notification settings - Fork 0
/
str.c
51 lines (38 loc) · 781 Bytes
/
str.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "common.h"
/* ɾ³ý¿Õ¸ñ */
void delSpace ( char * caBuf )
{
int i = 0, j = 0;
int iLen = strlen ( caBuf );
for ( i = 0; i < iLen; i++ )
{
if ( caBuf[i] != ' ' && caBuf[i] != '\t' )
caBuf[j++] = caBuf[i];
}
if ( caBuf[j-1] = '\n' )
caBuf[j-1] = '\0';
else
caBuf[j] = '\0';
}
/* È¡×Ö·û´® */
int doGetStringBySplit ( const char * caBuf, char * caSplitFlag, int iPosition, char * caData )
{
int iLen = 0, i = 0, j = 0;
char * pStr = NULL, * pEnd = NULL, * p = NULL;
iLen = strlen ( caBuf );
p = caBuf;
while ( i < iPosition )
{
pStr = p;
pEnd = strstr ( p, caSplitFlag );
if ( ! pEnd )
{
pEnd = caBuf + iLen;
break;
}
p = pEnd + strlen ( caSplitFlag );
i++;
}
memcpy ( caData, pStr, pEnd-pStr );
return 0;
}