-
Notifications
You must be signed in to change notification settings - Fork 4
/
myStr.c
94 lines (77 loc) · 1.41 KB
/
myStr.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "gamp.h"
//convert number to string
extern void num2str(int num, char *str, int len)
{
int i,j=0,n;
char tmp[MAXCHARS]={'\0'};
n=len-(int)(log10((float)num))-1;
if (n<0) {
tmp[0]='\0';
return;
}
for (i=0;i<n;i++) {
strcpy(&tmp[j++],"0");
}
sprintf(str,"%s%d%c",tmp,num,'\0');
}
//string clipping
extern void xStrMid (char *szDest, const int nPos, const int nCount, char *szSrc)
{
int i,n;
char *str,c;
n=strlen(szSrc);
if (n<=0) return;
str=szSrc+nPos;
for (i=0;i<nCount;i++) {
c=*(str+i);
if (c) {
*(szDest+i)=c;
}
else {
*(szDest+i)='\0';
break;
}
}
*(szDest+nCount) ='\0';
}
extern void trimSpace(char *strsrc)
{
int i=0,j=0,ps,pe;
int len=strlen(strsrc);
char str[MAXCHARS+1];
if (len<=0) return;
str[0]='\0';
strcpy(str,strsrc);
ps=0;
for (i=0;i<len;i++) {
if (*(str+i)!=' '&&*(str+i)!='\t') {
ps=i;
break;
}
}
pe=ps;
for (j=len-1;j>=0;j--) {
if (*(str+j)!=' '&&*(str+j)!='\t'&&*(str+j)!='\n') {
pe=j;
break;
}
}
if (pe==ps)
*(str+pe)='\0';
else
*(str+pe+1)='\0';
strcpy(strsrc,str+ps);
}
extern void cutFilePathSep(char *strPath)
{
int i,len;
for (i=0;i<4;i++) {
len=strlen(strPath);
if (len<=0)
break;
if (strPath[len-1]==FILEPATHSEP)
strPath[len-1]='\0';
else
break;
}
}