修剪字符串中的单引号 [英] trim a single quote from string

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

问题描述

如何修剪单个引号,即'从字符串开始到结束。

Thanx in Advance

How to trim a single quote i.e. ' from string start and from end.
Thanx in Advance

推荐答案

你可能已经想到了现在,通过查看 string 类的方法或通过快速搜索来实现这一点。



实际上有一组功能可以修剪字符串中的字符,这些是



修剪() - 删除所有前导和尾随空格

修剪(char []) - 删除指定字符的所有前导和尾随出现

TrimEnd(char []),TrimStart(char []) - 与Trim相同但仅限于字符串的开头或结尾



MSDN - 字符串 [< a href =http://msdn.microsoft.com/en-us/library/system.string.trimend.aspxtarget =_ blanktitle =New Window> ^ ]
You could have figured this out yourself by now, by looking at the methods that the string class has or by doing a quick search.

There are actually a set of function to trim chars off a string, these are

Trim() - Removes all leading and trailing white space
Trim(char[]) - Removes all leading and trailing occurrences of the characters specified
TrimEnd(char[]), TrimStart(char[]) - same as Trim but only on the start, or end of the string

MSDN - String[^]


这可能需要点亮更多的解释是要清楚你想要做什么。



但是,如果你的意思正是你所写的,那么我会想到两个选择



1.查找 String.Remove( int32,int32) [ ^ ]在MSDN上



2.查找 String.Replace(char / string,char / string) [ ^ ]。



如果你能保证,你应该只使用第二个选项你要删除的引号是唯一的。
This might require a little more explanation for it to be clear what it is that you want to do.

But, in case you mean exactly what you have written, two options spring to mind

1. Look up String.Remove(int32, int32)[^] on MSDN

2. Look up String.Replace(char/string, char/string)[^] on MSDN.

You should only use the second option if you can guarantee thet the quotes that you want to remove are the only ones.


在SK上阐述,这是我相信你正在寻找的实现:



Elaborating on SK, here is the implementation I believe you are looking for:

string e = "'REMOVE FRONT ' AND BACK '";
e.Trim('\'');


这篇关于修剪字符串中的单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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