本文整理汇总了C++中wstring::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::substr方法的具体用法?C++ wstring::substr怎么用?C++ wstring::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CharRight
wstring CharRight(const wstring& str, int length) {
if (length > static_cast<int>(str.length())) {
return str.substr(0, str.length());
} else {
return str.substr(str.length() - length, length);
}
}
示例2: RenameOldFile
bool CaffeineClientHandler::RenameOldFile(wstring filename)
{
// Determine if the file already exists. We do this because of the fugly extension
// API we're using.
#ifdef __APPLE__
return renameOldFile(filename);
#else
bool retval = false;
struct _stat buf = {0,};
if(_wstat(filename.c_str(), &buf) == 0)
{
wstring fileExt = L"";
unsigned index = filename.find_last_of('.');
if (index != wstring::npos)
{
fileExt = filename.substr(index);
}
wstringstream newFileName;
newFileName << filename.substr(0, index) << ".old" << fileExt;
RenameOldFile(newFileName.str());
_wrename(filename.c_str(), newFileName.str().c_str());
retval = true;
}
return retval;
#endif
}
示例3: parse_val
//////////////////////////////////////////////////////////////////////////
// parse_val
//////////////////////////////////////////////////////////////////////////
data_ptr parse_val(wstring key, data_map &data)
{
// quoted string
if (key[0] == L'\"')
{
return make_data(boost::trim_copy_if(key, boost::is_any_of(L"\""))) ;
}
// check for dotted notation, i.e [foo.bar]
size_t index = key.find(L".") ;
if (index == wstring::npos)
{
if (!data.has(key))
{
return make_data(L"{$" + key + L"}") ;
}
return data[key] ;
}
wstring sub_key = key.substr(0, index) ;
if (!data.has(sub_key))
{
return make_data(L"{$" + key + L"}") ;
}
data_ptr item = data[sub_key] ;
return parse_val(key.substr(index+1), item->getmap()) ;
}
示例4:
boost::optional< pair<wstring,wstring> > HTMLParser::AnalyzeLink( const wstring& rHtml, size_t uStartPos )
{
size_t uPos1 = rHtml.find( L"<a ", uStartPos );
if( uPos1 != wstring::npos )
{
size_t uPos2 = rHtml.find( L"href=\"", uPos1 );
if( uPos2 != wstring::npos )
{
uPos2 += 6;
uPos1 = rHtml.find( L"\"", uPos2 );
if( uPos1 != wstring::npos )
{
wstring sLinkUrl = rHtml.substr( uPos2, uPos1 - uPos2 );
uPos1 = rHtml.find( L">", uPos1 );
if( uPos1 != wstring::npos )
{
uPos1 += 1;
uPos2 = rHtml.find( L"</a>", uPos1 );
wstring sLinkText = rHtml.substr( uPos1, uPos2 - uPos1 );
boost::algorithm::trim( sLinkText );
return boost::optional< pair<wstring,wstring> >( make_pair( sLinkText, sLinkUrl ) );
}
}
}
}
return boost::optional< pair<wstring,wstring> >();
}
示例5: GetFileExtendName
wstring CStaticPubFunc::GetFileExtendName(wstring strFileName)
{
int intCharPosition;
//Find "\\",Get The File's Name
intCharPosition = strFileName.rfind(L'\\');
if(-1 != intCharPosition)
{
strFileName = strFileName.substr(intCharPosition - 1);
}
//AfxMessageBox(strFileName);
//Find ".",Get the file's extend name
intCharPosition = strFileName.rfind(L'.');
if(-1 != intCharPosition)
{
strFileName = strFileName.substr(intCharPosition - 1);
return strFileName;
}
else
{
//No extend name
return L"";
}
}
示例6: GetCurrentThreadId
filePathLinkW(const wstring& path) :m_ntType(L"\\??\\")
{
if (path.length() > 4 && path.substr(0, 4) == L"\\??\\")
{
m_ntType.append(path.substr(4));
}
else
{
m_ntType.append(path);
}
static DWORD tick = 0;
wchar_t tmpBuffer[100];
StringCbPrintfW(tmpBuffer, 100, L"%x%x%x%x", GetCurrentThreadId(), GetTickCount(), rand(), ++tick);
m_pathDefine = wstring(FS_BYPASS_DEFINE_PREFIX_W) + tmpBuffer;
if (DefineDosDeviceW(DDD_RAW_TARGET_PATH, m_pathDefine.c_str(), m_ntType.c_str()))
{
m_pathLink = wstring(L"\\\\.\\") + FS_BYPASS_DEFINE_PREFIX_W + tmpBuffer;
m_transformed = true;
}
else
{
m_pathLink = path;
m_transformed = false;
}
}
示例7:
vector<int> CJPWordsVector::makeTone(wstring str)
{
//目标整形数组
vector<int> tone;
//分割符为英文逗号
wchar_t flag = ',';
//起始位置
size_t start = 0;
//结束位置
size_t end = 0 ;
for( ; end<str.size(); end++ )
{
//当前符号位分隔符
if(str.at( end )== flag)
{
//截取子串
wstring numStr = str.substr(start,end-start);
//转换成数字加入数组
int num = _wtoi(numStr.c_str());
tone.push_back(num);
//跳过分割符
end++;
//移动开始位置
start = end;
}
}
//截取子串
wstring numStr = str.substr(start,end-start);
//转换成数字加入数组
int num = _wtoi(numStr.c_str());
tone.push_back(num);
return tone;
}
示例8: StrTokenizeStr
/**
Extract a vector of the substrings that are separated by the delimter string
\param str String to tokenize
\param tokens Return a vector of tokens
\param delimiter Delimeter string
\param trim true if all tokens should be trimmed (default), otherwise false
\param emptyTokens false if empty tokens should be removed from the result (default), otherwise true.
*/
void StrTokenizeStr(const wstring& str, vector<std::wstring>& tokens, const wstring& delimiter, bool trim/*=true*/, bool emptyTokens/*=false*/)
{
tokens.clear();
wstring::size_type lastPos = 0;
wstring::size_type pos = delimiter.empty()?wstring::npos:str.find(delimiter, lastPos);
while (wstring::npos != pos)
{
wstring tmp = str.substr(lastPos, pos - lastPos);
if ( ! tmp.empty() && trim)
{
tmp = StrTrim(tmp);
}
if ( ! tmp.empty() || emptyTokens)
{
tokens.push_back(tmp);
}
lastPos = pos + delimiter.length();
//if (pos != wstring::npos)
{
pos = str.find(delimiter, lastPos);
}
}
wstring tmp = str.substr(lastPos, wstring::npos);
if ( ! tmp.empty() && trim)
{
tmp = StrTrim(tmp);
}
if ( ! tmp.empty() || emptyTokens)
{
tokens.push_back(tmp);
}
}
示例9: ReadOneline
/*!
sakura.iniの1行を処理する.
1行の読み込みが完了するごとに呼ばれる.
@param line [in] 読み込んだ行
*/
void CProfile::ReadOneline(
const wstring& line
)
{
// 空行を読み飛ばす
if( line.empty() )
return;
//コメント行を読みとばす
if( 0 == line.compare( 0, 2, LTEXT("//") ))
return;
// セクション取得
// Jan. 29, 2004 genta compare使用
if( line.compare( 0, 1, LTEXT("[") ) == 0
&& line.find( LTEXT("=") ) == line.npos
&& line.find( LTEXT("]") ) == ( line.size() - 1 ) ) {
Section Buffer;
Buffer.strSectionName = line.substr( 1, line.size() - 1 - 1 );
m_ProfileData.push_back( Buffer );
}
// エントリ取得
else if( !m_ProfileData.empty() ) { //最初のセクション以前の行のエントリは無視
wstring::size_type idx = line.find( LTEXT("=") );
if( line.npos != idx ) {
m_ProfileData.back().mapEntries.insert( PAIR_STR_STR( line.substr(0,idx), line.substr(idx+1) ) );
}
}
}
示例10: bindBuiltinVariable
/***************************************************************************
* bindBuiltinVariable
***************************************************************************/
bool CCilVm::bindBuiltinVariable( const wstring& strQualifiedName,
CVariable* const pvar )
{
bool bReturn = true;
//Bind the var
if( strQualifiedName.find( STRING_INTERNAL_SCOPEDELIMITER ) != wstring::npos )
{
wstring strRoot = strQualifiedName.substr( 0, strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) );
assert( strRoot.find( STRING_INTERNAL_SCOPEDELIMITER ) == wstring::npos );
wstring strLeaf = strQualifiedName.substr( strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) + 1,
strQualifiedName.length() );
RID ridObject = getMetaData().queryBuiltinObjectRid( strRoot );
if( ridObject == RID_NOTDEFINED )
return false;
//Create property
getPrototypeObject( ridObject ).setProperty( strLeaf,
*pvar );
}
return bReturn;
}
示例11: if
/// <summary>Parses the file ID of a language file</summary>
/// <param name="fn">The filename including extension</param>
LanguageFilenameReader::LanguageFilenameReader(const wstring& fn) : HasLanguage(false), FileID(0), Valid(false)
{
try
{
// Ensure extension is XML/PCK
if (Path(fn).HasExtension(L".xml") || Path(fn).HasExtension(L".pck"))
{
// No language ID: nnnn.pck
if (fn.length() == 4+4)
FileID = ParseFileID(fn.substr(0,4));
// X3R: LLnnnn.pck
else if (fn.length() == 6+4)
{
FileID = ParseFileID(fn.substr(2,4));
Language = ParseLanguageID(fn.substr(0,2));
HasLanguage = true;
}
// X3TC: nnnn-L0nn.pck
else if (fn.length() == 9+4)
{
FileID = ParseFileID(fn.substr(0,4));
Language = ParseLanguageID(fn.substr(7,2));
HasLanguage = true;
}
// Validate
Valid = FileID > 0;
}
}
catch (...)
{
Valid = false;
}
}
示例12: SetDetailedVersion
/**
Gather the Major and Minor version from Product version
Parameters: version - Product version, its format like 11.23.32, REV- or 0.4b41
*/
void InstalledSoftwareInstance::SetDetailedVersion(const wstring& version)
{
size_t pos = version.find_first_of('.');
if( pos != wstring::npos )
{
wstring left = version.substr(0, pos);
wstring right = version.substr(pos+1);
try
{
m_versionMajor = StrToUInt(left);
// Exclude characters
for(pos = 0; pos< right.size(); pos++)
{
if( right[pos] < '0' || right[pos] > '9' ) {
break;
}
}
if(pos > 0) {
left = right.substr(0, pos);
m_versionMinor = StrToUInt(left);
}
}
catch (const SCXException& e)
{
SCX_LOGWARNING(m_log, StrAppend(L"parse InstalledSoftwareInstance version fails:", version).append(L" - ").append(e.What()));
}
}
}
示例13: WinMain
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParamarg, int cmdShow) {
openLog();
#ifdef _NEED_WIN_GENERATE_DUMP
_oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter);
#endif
writeLog(L"Updaters started..");
LPWSTR *args;
int argsCount;
bool needupdate = false, autostart = false, debug = false;
args = CommandLineToArgvW(GetCommandLine(), &argsCount);
if (args) {
for (int i = 1; i < argsCount; ++i) {
if (equal(args[i], L"-update")) {
needupdate = true;
} else if (equal(args[i], L"-autostart")) {
autostart = true;
} else if (equal(args[i], L"-debug")) {
debug = _debug = true;
openLog();
}
}
if (needupdate) writeLog(L"Need to update!");
if (autostart) writeLog(L"From autostart!");
exeName = args[0];
writeLog(L"Exe name is: " + exeName);
if (exeName.size() > 11) {
if (equal(exeName.substr(exeName.size() - 11), L"Updater.exe")) {
exeDir = exeName.substr(0, exeName.size() - 11);
writeLog(L"Exe dir is: " + exeDir);
if (needupdate && update()) {
updateRegistry();
}
} else {
writeLog(L"Error: bad exe name!");
}
} else {
writeLog(L"Error: short exe name!");
}
LocalFree(args);
} else {
writeLog(L"Error: No command line arguments!");
}
wstring targs = L"-noupdate";
if (autostart) targs += L" -autostart";
if (debug) targs += L" -debug";
ShellExecute(0, 0, (exeDir + L"Telegram.exe").c_str(), targs.c_str(), 0, SW_SHOWNORMAL);
writeLog(L"Executed Telegram.exe, closing log and quiting..");
closeLog();
return 0;
}
示例14: GetNextValue
HRESULT CDataTuple::GetNextValue(int &iVal, wstring &line, size_t &start)
{
HRESULT hRet = E_FAIL;
size_t end;
wstring sep(TEXT(" \t"), 1);
if (start >= line.length())
{
return hRet;
}
end = line.find_first_of (sep, start+1);
wstring substr;
if (string::npos != end && end > start)
{
substr = line.substr(start, end -start);
}
else
{
substr = line.substr(start, line.length() -start);
}
if (substr.length() > 0)
{
float val;
if (1 == _stscanf_s(substr.c_str(), TEXT("%f"), &val))
{
iVal = (int)val;
hRet = S_OK;
}
}
else
{
start = string::npos;
}
if (SUCCEEDED(hRet) && end != string::npos)
{
start = line.find(sep, end);
while (start < line.length() && line[start +1] == ' ')
{
++start;
}
}
else
{
start = string::npos;
}
return hRet;
}
示例15: HexToARGB
COLORREF HexToARGB(const wstring& text) {
int i = text.length() - 6;
if (i < 0) return 0;
unsigned int r, g, b;
r = wcstoul(text.substr(i + 0, 2).c_str(), NULL, 16);
g = wcstoul(text.substr(i + 2, 2).c_str(), NULL, 16);
b = wcstoul(text.substr(i + 4, 2).c_str(), NULL, 16);
return RGB(r, g, b);
}