|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 @8 t$ e5 }8 Z; V4 i! g1 L+ M- u& X' g2 o6 L6 y% b' n( ~( o
# R* F: p ^# a3 ?, ]8 I. b
UG NX二次开发源码:快速找到字符串后缀为数字的位置% {4 T- A% `5 ?$ M+ m' \( c! R) x7 ?1 @
, @6 r, p1 U9 b做了个简单的测试,这个比较常用,分享下!+ ?7 L1 E0 D! G6 X r* f
6 _- O3 f8 ~6 Z+ Y9 {4 Q8 C
#include <iostream>( P2 S. f1 g) P8 l
#include <stdio.h>
+ Y6 ?0 O0 G1 H$ d* y* \#include <stdlib.h>) s! g7 E0 T( \
#include <string> z" i* e# I6 x7 L# V* l
* f) g4 n9 Y' h d' Yusing namespace std;
0 F* Q" }/ S" U% \# F
- s7 X$ L0 M9 l* v& x" [int main()4 c' J% x0 d y; L9 F. _8 a
{
5 j. `( A/ k, m+ N string s1;6 \ A/ G- M: c/ u# {
s1 = "111ddd1112ff221";
% _7 [5 Q, y- F' C std::cout << "Input str:" << s1<< endl;& c3 E$ M0 T. f+ b0 i& c2 `; o
int pos = 0;
: t- I4 Y o/ a- y$ |8 C6 U
( }; i8 U' ^. v/ } for(int i=s1.size()-1 ; i>=0;i--)3 A& _# H# {2 y! `4 j& J4 f
{
7 d: F8 t0 ~5 V5 ]% ` std::cout << s1.at(i)<< pos<< endl;0 y# A% I2 @% Q" d4 S- I8 g2 N
if ( s1.at(i)<='9' && s1.at(i) >= '0') // digit
/ d! L6 A9 {/ d& Z/ k$ _1 K% I/ n {9 J' z! q2 m$ v5 i. O
pos++;: l+ @! Z$ J0 i2 h5 Q6 d v# ?- S# \1 l
continue;
8 s8 l7 _* D$ J# z; r. C" | }- ^. D& w# |+ A$ Y+ n- L
else
( b5 g+ `# g+ s5 F {0 f. P* T: ]' E. F- S
break;
% y% u" l1 s, \- E } 8 h1 j3 D" a/ u7 q) b, w- S
}
4 G% Q( F. h4 B" J
3 k; f% N& L9 h# _6 }5 q std::cout << "outPut pos:" << pos<< endl;
& T" q0 {- s' B$ ? std::cout << "outPut str:" << s1.substr(s1.length()-pos,pos)<< endl;
" @6 g' C# p- Y+ G7 m/ R
! R% f" }& C2 d$ d, t. R}9 ]1 M p. D* X2 P- t$ V6 m. v# Q- n
# D- }) Q# T8 y- |0 j3 g7 I
|
|