long find_wchar(IN WCHAR* sChar, IN WCHAR* sItem) {
long nRet = -1;
long K = 0, nLen = lstrlen(sChar);
for (K = 0; K < nLen; K++) {
if (sChar[K] == sItem[0]) { nRet = K; }
}
return nRet;
}
void reverse(WCHAR str[], long length) {
int start = 0;
int end = length -1;
while (start < end) {
swap(*(str + start), *(str + end));
start++;
end--;
}
}
WCHAR* RTRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
long nLength = lstrlen(sBuf);
long nLen = lstrlen(sChar);
if ((nLength) && (nLen)) {
while (nLength > 0) {
nLength -= 1;
if (find_wchar(sChar, &sBuf[nLength]) > -1) {
sBuf[nLength] = L'\0';
} else {
break;
}
}
}
return sBuf;
}
WCHAR* LTRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
reverse(sBuf, lstrlen(sBuf));
sBuf = RTRIM(sBuf, sChar);
reverse(sBuf, lstrlen(sBuf));
}
WCHAR* TRIM(IN WCHAR* sBuf, IN WCHAR* sChar) {
return LTRIM(RTRIM(sBuf, sChar), sChar);
}
typedef String fstring;
int _tmain ()
{
fstring s1(_T("Zero, One, Two , Three , Four, Five , Six, Seven, Eight , Nine, Ten,"));
s1.Print( true);
s1 = s1.Remove(_T(" "));
s1.Print( true);
// Remove Trailing comma
s1.RTrim(44);
s1.Print( true);
}
changed in Strings.h:
[code]
void LTrim(int charToTrim=32); // Removes leading white space by modifying existing String
void RTrim(int charToTrim=32); // Removes trailing white space by modifying existing String
void Trim(int charToTrim=32); // Removes leading or trailing white space from existing String
void String::LTrim(int charToTrim)
{
size_t iCt=0;
for(size_t i=0; i<this->iLen; i++)
{
if(this->lpBuffer[i]==9||this->lpBuffer[i]==10||this->lpBuffer[i]==13||this->lpBuffer[i]==32||this->lpBuffer[i]==charToTrim)
iCt++;
else
break;
}
if(iCt)
{
for(size_t i=iCt; i<=this->iLen; i++)
this->lpBuffer[i-iCt]=this->lpBuffer[i];
}
this->iLen=this->iLen-iCt;
this->blnSucceeded=TRUE;
}
void String::RTrim(int charToTrim)
{
int iCt=0;
for(int i=this->iLen-1; i>0; i--)
{
if(this->lpBuffer[i]==9||this->lpBuffer[i]==10||this->lpBuffer[i]==13||this->lpBuffer[i]==32||this->lpBuffer[i]==charToTrim )
iCt++;
else
break;
}
this->lpBuffer[this->iLen-iCt]=0;
this->iLen=this->iLen-iCt;
this->blnSucceeded=TRUE;
}
void String::Trim(int charToTrim)
{
this->LTrim(charToTrim);
this->RTrim(charToTrim);
this->blnSucceeded=TRUE;
}
// cl Test03.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
#define UNICODE
#define _UNICODE
#include <windows.h>
#include "stdio.h"
#include "Strings.h"
int main()
{
String* pStrs=NULL;
int iCnt=0;
String s;
s=L" one , two , three, four , five , six";
s.Print(true);
iCnt=s.ParseCount(L',');
pStrs=new String[iCnt];
s.Parse(pStrs,L',',iCnt);
for(size_t i=0; i<iCnt; i++)
pStrs[i].Print(false);
printf("\n");
for(size_t i=0; i<iCnt; i++)
{
pStrs[i].Trim();
pStrs[i].Print(false);
}
delete [] pStrs;
getchar();
return 0;
}
#if 0
C:\Code\VStudio\VC++9\Silvah\Sil7>Test02
one , two , three, four , five , six
one two three four five six
onetwothreefourfivesix
#endif
// cl Test02.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
#define UNICODE
#define _UNICODE
#include <windows.h>
#include "stdio.h"
#include "Strings.h"
int main()
{
String s,s1;
s=L" one , two , three, four , five , six";
s.Print(true);
s1=s.Remove(L" ");
s1.Print(true);
getchar();
return 0;
}
#if 0
C:\Code\VStudio\VC++9\Silvah\Sil7>cl Test02.cpp Strings.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Test02.cpp
Strings.cpp
Generating Code...
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
/out:Test02.exe
Test02.obj
Strings.obj
TCLib.lib
kernel32.lib
user32.lib
C:\Code\VStudio\VC++9\Silvah\Sil7>Test02
one , two , three, four , five , six
one,two,three,four,five,six
#endif
Quote from: Patrice Terrier on June 15, 2017, 02:09:37 PMVisual Studio plus few Extensions:
Visual Studio, has a built-in debugger, intellisense, and all extra goodies you can expect from a modern compiler.
Page created in 0.074 seconds with 11 queries.