[解决]如何在C#或SQL查询中修剪字符串的文本。 [英] [Solved] How to Trim Text of a string in C# or in SQL query.

查看:100
本文介绍了[解决]如何在C#或SQL查询中修剪字符串的文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有以下sql查询:



Hi guys,

I have the following sql query:

"select task_attachment_path \"File Name\" from AttachmentTable";





我在gridview的单元格中得到了输出:



|文件名|

| ====================================== |

| D:\ Live CMS \requestAttachments\23101 \Development File.txt |



我想在我的Gridview Cell中仅显示文件名,如'开发文件.txt'只。

我可以在我的SQL查询中应用任何类型的函数,或者如何在我的C#代码中处理它。



请帮助!!!



谢谢,

AR



I got the output in my gridview's cell as:

| File Name |
| ====================================== |
| D:\Live CMS\requestAttachments\23101\Development File.txt |

I want to show only File Name in my Gridview Cell like 'Development File.txt' only.
Can I apply any kind of function in my SQL query or how can I handle it in my C# code.

Please help !!!

Thanks,
AR

推荐答案

使用 Path.GetFileName [< a href =http://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]方法(参见文档页面中的示例代码)。
Use the Path.GetFileName[^] method (see the sample code in the documentation page).


访问这里...



< a href =http://msdn.microsoft.com/en-us/library/t97s7bs3%28v=vs.110%29.aspx> http://msdn.microsoft.com/en-us/library/t97s7bs3 %28v = vs.110%29.aspx [ ^ ]







http://www.w3resource.com/sql /character-functions/trim.php [ ^ ]
visit here...

http://msdn.microsoft.com/en-us/library/t97s7bs3%28v=vs.110%29.aspx[^]

or

http://www.w3resource.com/sql/character-functions/trim.php[^]


您可以使用 SUBSTRING sql中的[ ^ ]。 />


例如



You can use SUBSTRING[^] in sql.

e.g

select substring('select task_attachment_path \"File Name\" from AttachmentTable',31,9)


这篇关于[解决]如何在C#或SQL查询中修剪字符串的文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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