如何从文本中删除某些前导字符
How do I remove certain leading characters from text
如何从文本列中删除字符 =、?、+、- 和 @,但前提是它们在字符串中显示为前缀?
例如:
Input
Output
#Whosebug
Whosebug
@#Whosebug
Whosebug
=?+-Whosebug
Whosebug
假设“前缀”意味着删除第一个 non-special 字符左侧的字符,但字符串后面的特殊字符应保留:
with data as (
select '@#Whosebug' string union all
select '=?+Stack#@Overflow' union all
select 'Stack#@Overflow'
)
select * , Stuff(string,1,p.pos-1,'')
from data
cross apply(values(PatIndex('%[^=?+-@#]%',string)))p(pos);
Original
Fixed
@#Whosebug
Whosebug
=?+Stack#@Overflow
Stack#@Overflow
Stack#@Overflow
Stack#@Overflow
如何从文本列中删除字符 =、?、+、- 和 @,但前提是它们在字符串中显示为前缀?
例如:
Input | Output |
---|---|
#Whosebug |
Whosebug |
@#Whosebug |
Whosebug |
=?+-Whosebug |
Whosebug |
假设“前缀”意味着删除第一个 non-special 字符左侧的字符,但字符串后面的特殊字符应保留:
with data as (
select '@#Whosebug' string union all
select '=?+Stack#@Overflow' union all
select 'Stack#@Overflow'
)
select * , Stuff(string,1,p.pos-1,'')
from data
cross apply(values(PatIndex('%[^=?+-@#]%',string)))p(pos);
Original | Fixed |
---|---|
@#Whosebug | Whosebug |
=?+Stack#@Overflow | Stack#@Overflow |
Stack#@Overflow | Stack#@Overflow |