本文整理汇总了C++中TStr::SplitOnCh方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::SplitOnCh方法的具体用法?C++ TStr::SplitOnCh怎么用?C++ TStr::SplitOnCh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::SplitOnCh方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(TStr, SplitOnCh) {
const TStr Str = "abcde";
const TStr EmptyStr = "";
TStr LStr, RStr;
// middle
Str.SplitOnCh(LStr, 'c', RStr);
ASSERT_EQ(LStr, "ab");
ASSERT_EQ(RStr, "de");
// non-existent
Str.SplitOnCh(LStr, 'g', RStr);
ASSERT_EQ(LStr, "abcde");
ASSERT_EQ(RStr, "");
// first
Str.SplitOnCh(LStr, 'a', RStr);
ASSERT_EQ(LStr, "");
ASSERT_EQ(RStr, "bcde");
// last
Str.SplitOnCh(LStr, 'e', RStr);
ASSERT_EQ(LStr, "abcd");
ASSERT_EQ(RStr, "");
// empty
EmptyStr.SplitOnCh(LStr, 'a', RStr);
ASSERT_EQ(LStr, "");
ASSERT_EQ(RStr, "");
}
示例2: ReadGraph
void ReadGraph(TStr& InFile, bool& Directed, bool& Weighted, bool& Verbose, PWNet& InNet) {
TFIn FIn(InFile);
int64 LineCnt = 0;
try {
while (!FIn.Eof()) {
TStr Ln;
FIn.GetNextLn(Ln);
TStr Line, Comment;
Ln.SplitOnCh(Line,'#',Comment);
TStrV Tokens;
Line.SplitOnWs(Tokens);
if(Tokens.Len()<2){ continue; }
int64 SrcNId = Tokens[0].GetInt();
int64 DstNId = Tokens[1].GetInt();
double Weight = 1.0;
if (Weighted) { Weight = Tokens[2].GetFlt(); }
if (!InNet->IsNode(SrcNId)){ InNet->AddNode(SrcNId); }
if (!InNet->IsNode(DstNId)){ InNet->AddNode(DstNId); }
InNet->AddEdge(SrcNId,DstNId,Weight);
if (!Directed){ InNet->AddEdge(DstNId,SrcNId,Weight); }
LineCnt++;
}
if (Verbose) { printf("Read %lld lines from %s\n", (long long)LineCnt, InFile.CStr()); }
} catch (PExcept Except) {
if (Verbose) {
printf("Read %lld lines from %s, then %s\n", (long long)LineCnt, InFile.CStr(),
Except->GetStr().CStr());
}
}
}
示例3: Split
void TFtrGenSparseNumeric::Split(
const TStr& Str, int& Id, TStr& Val) const {
if (!Str.IsChIn(':')) { TExcept::Throw("Wrong sparse numeric '" + Str + "'!"); }
//split
TStr IdStr; Str.SplitOnCh(IdStr, ':', Val);
// parse id
if (!IdStr.IsInt(Id)) { TExcept::Throw("Wrong sparse numeric '" + Str + "'!"); }
}
示例4: GetVarNmV
void TEnv::GetVarNmV(TStrV& VarNmV) {
VarNmV.Clr();
int VarN = 0;
while (_environ[VarN] != NULL) {
TStr VarNmVal = _environ[VarN++];
TStr VarNm;
TStr VarVal;
VarNmVal.SplitOnCh(VarNm, '=', VarVal);
VarNmV.Add(VarNm);
}
}
示例5: getWebsite
inline TStr getWebsite(TStr fulladdress)
{
TStr left,right,tmp,res;
if(fulladdress.SearchStr(TStr("http"),0)>=0)
{
fulladdress.SplitOnStr(left,TStr("//"),right);
right.SplitOnCh(res,'/',tmp);
}
else
{
fulladdress.SplitOnCh(res,'/',tmp);
}
return res;
}
示例6: OnGetHost
void TWebPgFetchEvent::OnGetHost(const PSockHost& SockHost) {
if (SockHost->IsOk()){
UrlStrV.Add(CurUrl->GetUrlStr());
OppSockClosed=false;
SockMem.Clr();
Sock=TSock::New(this);
int PortN;
if (ProxyStr.Empty()){
PortN=CurUrl->GetPortN();
} else {
TStr ProxyHostNm; TStr PortNStr;
ProxyStr.SplitOnCh(ProxyHostNm, ':', PortNStr);
PortN=PortNStr.GetInt(80);
}
Sock->PutTimeOut(TimeOutMSecs);
Sock->Connect(SockHost, PortN);
} else {
OnFetchError("Invalid Host");
}
}