|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 p3 w- ]# \1 F4 J' d7 d& R) d2 Z0 s" f4 ^ I4 @9 a
# N, y2 E7 }( KUG NX二次开发源码:快速找到字符串后缀为数字的位置8 K5 @( y1 O" R* b
/ q \4 m& I7 j' w
做了个简单的测试,这个比较常用,分享下!# y' R! s; L; C* P. k U: D- w! @9 f4 o
5 X ]. n+ S* l& F5 y6 N) j#include <iostream>4 t/ y& }- d2 G+ p! p; ^# c
#include <stdio.h>" l4 r1 |% ]$ x/ C9 `! B# e
#include <stdlib.h>
2 }8 M& J6 p1 {#include <string>
" X$ K* n5 w2 |" i8 E! @- k
( N" x) y0 X8 ^. S& x6 y. Busing namespace std;
+ E V2 c7 R0 d# K r' V; `: _
6 H. _. S- M4 S! i7 _5 ~int main()
: O7 Y6 V' z7 E0 I: j ?" K{
9 [) P+ x+ g* V( G' z. V& b string s1;
+ b& b5 h2 T, p9 D1 ] s1 = "111ddd1112ff221";6 v7 ]# t5 d: h3 J% y
std::cout << "Input str:" << s1<< endl;
" P8 j. h8 z/ b. z4 C7 U$ F int pos = 0;
8 a& I8 W, c. z9 I/ W) x# @+ v8 P! @1 M3 M9 V f }; F
for(int i=s1.size()-1 ; i>=0;i--)+ k' X" G4 e, }4 U2 B
{
% W% s$ Q3 I4 P; A8 O( V/ |$ e& k$ _ std::cout << s1.at(i)<< pos<< endl;
* L; L9 `- G9 v: Y8 c; ^9 H if ( s1.at(i)<='9' && s1.at(i) >= '0') // digit
2 l* `- f& p, \7 X: l! C* L# c1 Q. ^ {
& B! ^5 s& C; O( ]. o pos++;) [) w4 A7 ^; h( t0 t/ T
continue;
9 a1 i# K& S8 b( z+ O; d2 l; A }% d4 E8 v2 _$ g0 `5 e3 r8 K
else
& a3 t B4 ^6 |" O {% [5 l8 Y* S5 \$ f
break;8 t( t* f% O6 M) u* z- q& m7 l: B5 g
} 7 ]5 X( {; e, f6 w. p/ R3 ~
}2 R, R: ^- v Q2 `, p, a
I) T I( V/ J4 t- c- T. b4 e std::cout << "outPut pos:" << pos<< endl;
2 G' t) ?* P, W" \( H+ W1 @ std::cout << "outPut str:" << s1.substr(s1.length()-pos,pos)<< endl;
7 H1 t4 D& l5 M) Q, ^1 \) _. Y+ i- D0 { g% ~% Q* R* i
}. V4 B1 H+ M: r f
9 s$ z) Y) j; ?$ M- h |
|