// MathFuncsDll.cpp
//
#include "MyStringFunc.h"
#include <stdexcept>
#include <string>
#include <stdio.h>
#include <stdlib.h>
namespace StringFuncs
{
SString MyStringFunc::RemoveStringSpcaeChar( const SString& strIn )
{
const char ansiSpace = ' ';
const char doubleSpace[3] = " ";
SString strMid;
SString strOut;
SString::size_type sB = 0;
SString::size_type sE = strIn.find_first_of(ansiSpace);
SString::size_type sLen = strIn.size();
do
{
if (sE == SString::npos)
{
strMid += strIn.substr(sB);
break;
}
strMid += strIn.substr(sB,sE-sB);
sE += 1;
if (sE >= sLen)
{
break;
}
sB = sE;
sE = strIn.find(ansiSpace,sB);
} while (true);
sE = 0;
sLen = strMid.size();
do
{
if (sE + 2 > sLen)
{
strOut += strMid.substr(sE);
break;
}
SString strOp = strMid.substr(sE,2);
if (strOp.at(0) != doubleSpace[0]||strOp.at(1) != doubleSpace[1])
{
strOut += strMid.substr(sE,2);
}
sE += 2;
} while (true);
return strOut;
}
bool MyStringFunc::IsInt( const SString& strIn, int nBase )
{
bool bResult;
int nLen = strIn.size();
char* pStr = (char*) strIn.c_str();
bResult = (nLen>0)&&!isspace(pStr[0]);
if (bResult)
{
char* endp;
strtol(pStr,&endp,nBase);
bResult = (endp - pStr == nLen);
}
return bResult;
}
bool MyStringFunc::IsFloat( const SString& strIn )
{
bool bResult;
int nLen = strIn.size();
char* pStr = (char*) strIn.c_str();
bResult = (nLen>0)&&!isspace(pStr[0]);
if (bResult)
{
char* endp;
strtod(pStr,&endp);
bResult = (endp - pStr == nLen);
}
return bResult;
}
SString MyStringFunc::Trim( SString& strIn )
{
if (strIn.empty())
{
return strIn;
}
strIn.erase(strIn.find_last_not_of(" \t\r\n")+1);
strIn.erase(0,strIn.find_first_not_of(" \t\r\n"));
return strIn;
}
}
// MathFuncsDll.h
#pragma once
#include <string>
namespace StringFuncs
{
typedef std::string SString;
class MyStringFunc
{
public:
// Returns string with spcae
static __declspec(dllexport) SString RemoveStringSpcaeChar(const SString& strIn);
// Returns Bool is Int
static __declspec(dllexport) bool IsInt(const SString& strIn, int nBase);
// Returns Bool is Float
static __declspec(dllexport) bool IsFloat(const SString& strIn);
// Returns string with no spcae
static __declspec(dllexport) SString Trim(SString& strIn);
};
}
// MyExecRefsDll.cpp
//
#include <iostream>
#include "MathFuncsDll.h"
#include "MyStringFunc.h"
using namespace std;
int main()
{
str1 = StringFuncs::MyStringFunc::RemoveStringSpcaeChar(str1);
cout<< str1 <<endl;
string str2 ="123. 01";
bool bo1 = StringFuncs::MyStringFunc::IsInt(str2,10);
bool bo2 = StringFuncs::MyStringFunc::IsFloat(str2);
if (bo2)
{
cout<<1.10<<endl;
}
system("pause");
return 0;
}