如何在特定字符之前替换字符串的子字符串? [英] How do I replace a substring of a string before a specific character?

查看:40
本文介绍了如何在特定字符之前替换字符串的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表格电子邮件:

值:

josh@yahoo.com
carmine32@hotmail.com
zehmaneh@yahoo.com

我想用 test 替换 @ 之前的字符串.

I want to replace the string before @ with test.

结果:

test@yahoo.com
test@hotmail.com
test@yahoo.com

如何使用子串并根据字符串中的字符进行替换?

How do I use substringing and replace based on a character in the string?

推荐答案

你甚至不需要使用substringreplace,你可以使用这个:>

You don't even need to use substring or replace, you can use this:

SELECT 'test' + RIGHT(email, charindex('@', REVERSE(email)))
FROM YourTable

你可以用这个来测试一下:

You can test it out with this:

DECLARE @email nvarchar(50)
SET @email = 'carmine32@hotmail.com'
PRINT 'test' + RIGHT(@email, charindex('@', REVERSE(@email)))

这篇关于如何在特定字符之前替换字符串的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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