本文整理汇总了C++中TStr::SplitOnLastCh方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::SplitOnLastCh方法的具体用法?C++ TStr::SplitOnLastCh怎么用?C++ TStr::SplitOnLastCh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::SplitOnLastCh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAuthNmVPubStr
void TGgSchRef::GetAuthNmVPubStr(
const TStr& AuthNmVPubStr, TStrV& AuthNmV, TStr& PubNm, TStr& PubYearStr){
// split input string into two parts
TStr AuthNmVStr; TStr PubStr;
AuthNmVPubStr.SplitOnStr(AuthNmVStr, " - ", PubStr);
// author-names string
AuthNmVStr.SplitOnAllCh(',', AuthNmV, true);
for (int AuthN=0; AuthN<AuthNmV.Len(); AuthN++){
AuthNmV[AuthN].ToTrunc();
}
if ((!AuthNmV.Empty())&&
((AuthNmV.Last().IsStrIn("..."))||(AuthNmV.Last().Len()<=2))){
AuthNmV.DelLast();
}
// publication-name & publication-year string
TStr OriginStr; TStr LinkStr;
PubStr.SplitOnStr(OriginStr, " - ", LinkStr);
OriginStr.SplitOnLastCh(PubNm, ',', PubYearStr);
PubNm.ToTrunc(); PubYearStr.ToTrunc();
if ((PubYearStr.Len()>=4)&&(PubYearStr.GetSubStr(0, 3).IsInt())){
PubYearStr=PubYearStr.GetSubStr(0, 3);
} else
if ((PubNm.Len()>=4)&&(PubNm.GetSubStr(0, 3).IsInt())){
PubYearStr=PubNm.GetSubStr(0, 3); PubNm="";
} else {
PubYearStr="";
}
}
示例2:
///// Split on last occurrence of SplitCh, return Pair of Left/Right strings
///// if the character is not found the whole string is returned as the right side
//void SplitOnLastCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
TEST(TStr, SplitOnLastCh) {
const TStr Str = "abcd";
const TStr Str2 = "a";
const TStr EmptyStr = "";
TStr LStr, RStr;
// left empty
Str.SplitOnLastCh(LStr, 'a', RStr);
EXPECT_EQ(LStr, "");
EXPECT_EQ(RStr, "bcd");
// right empty
Str.SplitOnLastCh(LStr, 'd', RStr);
EXPECT_EQ(LStr, "abc");
EXPECT_EQ(RStr, "");
// both
Str2.SplitOnLastCh(LStr, 'a', RStr);
EXPECT_EQ(LStr, "");
EXPECT_EQ(RStr, "");
// both nonempty
Str.SplitOnLastCh(LStr, 'b', RStr);
EXPECT_EQ(LStr, "a");
EXPECT_EQ(RStr, "cd");
// no-match
Str.SplitOnLastCh(LStr, 'x', RStr);
EXPECT_EQ(LStr, "");
EXPECT_EQ(RStr, Str);
// empty
EmptyStr.SplitOnLastCh(LStr, 'a', RStr);
EXPECT_EQ(LStr, "");
EXPECT_EQ(RStr, "");
}