Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2012-05-15 : 11:28:55
|
| i need to parse a string like [p]a]a]s]s][p when a [ sign occurs then next letter need to be convert in upper case and when a ]sign occurs the next letter need to be convert in lower case.the sign [and ] need to be removed the desired output of is : [p]a]a]s]s][p string is PaassP please helpchallenge everything |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-15 : 11:42:23
|
[code]declare @str varchar(20) = '[p]a]a]s]s][p'declare @pos intselect @pos = charindex('[', @str)while @pos <> 0begin select @str = stuff(@str, @pos + 1, 1, upper(substring(@str, @pos + 1, 1))) select @pos = charindex('[', @str, @pos + 1)endselect replace(replace(@str, '[', ''), ']', '')[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-15 : 22:26:50
|
| [code]declare @str varchar(20) = '[p]a]a[s]s][p',@rstr varchar(20)declare @pos int;With Num(N)AS(SELECT 1UNION ALLSELECT N+1FROM NumWHERE N+1 <= LEN(@str))select @rstr=COALESCE(@rstr,'') + CASE WHEN SUBSTRING(@str,N-1,1)='[' THEN UPPER(SUBSTRING(@str,N,1)) WHEN SUBSTRING(@str,N-1,1)=']' THEN LOWER(SUBSTRING(@str,N,1)) ELSE SUBSTRING(@str,N,1) ENDfrom NumWHERE N >1AND SUBSTRING(@str,N,1) NOT IN ('[',']')select @rstr[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2012-05-20 : 23:35:30
|
| resolved... thanks challenge everything |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-21 : 16:19:53
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|