Asp.net子字符串 [英] Asp.net Substring

查看:146
本文介绍了Asp.net子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FROM LABO VAN VOOREN \ Geomeasuring&分析nv \ BORING \ gfh \ 171210 \ attendence.pdf

上面提到的是一个字符串.我想从中获取子字符串.

我只想使用子字符串''attendence.pdf''

同样

来自LABO VAN VOOREN \ Geomeasuring& nv \ BORING \ gfh \ 171210 \ fromtheliveofthearticle.pdf

我只想使用子字符串"fromtheliveofthearticle.pdf"


需要的是,每次我得到像上面的字符串这样的路径时,每次我只想要"\"符号后的姓氏.

请帮助解决此问题

Kishore

FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf

The above mentioned is a string.i want to take substring from that.

i want to take the substring ''attendence.pdf'' only

Similarly

FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\fromtheliveofthearticle.pdf

i want to take the substring ''fromtheliveofthearticle.pdf'' only
etc

The need is that every time i get a path like the string above,each time i want only the last name after ''\'' symbol.

Kindly help to solve this

Kishore

推荐答案

尝试myString.SubString(myString.LastIndexOf("\\")).


谢谢您的提问.您可以按照下面的代码.

Thank you for your question. You can follow the bellow code.

String strOutput = String.Empty;

//attendence.pdf
String strTemp=@"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf";
String [] strArray = strTemp.Split(new Char [] {'\\'});
strOutput = strArray[strArray.Length - 1];//attendence.pdf

//fromtheliveofthearticle.pd
strTemp = @"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\fromtheliveofthearticle.pdf";
strArray = strTemp.Split(new Char[] { '\\' });
strOutput = strArray[strArray.Length - 1]; //fromtheliveofthearticle.pd




谢谢,
Mamun




Thanks,
Mamun


假设您将字符串存储在名为"path"的变量中.
因此,这就是获取文件名部分的方式.

Suppose you have the string stored in a variable called ''path''.
So, this is how you get the file name part.

string path = @"FROM LABO VAN VOOREN\Geomeasuring & Analysis nv\BORING\gfh\171210\attendence.pdf";
string fileName = path.Substring(path.LastIndexOf("\\") + 1);


这篇关于Asp.net子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆