[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Delete character bottom string

luigi.zambetti

3/9/2007 9:57:00 AM

Hi all,
I have some strings like these:

aa/aa//
//
aa//
4/5/6/7

I want delete the character "/" when is at the bottom of the string,
or the string is only /.
So to obtain:

aa/aa
Null
aa
4/5/6/7

How can I get this?

Thanks a lot.

Luigi

4 Answers

masri999

3/9/2007 10:12:00 AM

0

Try replace (string,'//','/')


On Mar 9, 2:57 pm, "ciupaz" <luigi.zambe...@gmail.com> wrote:
> Hi all,
> I have some strings like these:
>
> aa/aa//
> //
> aa//
> 4/5/6/7
>
> I want delete the character "/" when is at the bottom of the string,
> or the string is only /.
> So to obtain:
>
> aa/aa
> Null
> aa
> 4/5/6/7
>
> How can I get this?
>
> Thanks a lot.
>
> Luigi


luigi.zambetti

3/9/2007 10:14:00 AM

0

On 9 Mar, 11:12, "M A Srinivas" <masri...@gmail.com> wrote:
> Try replace (string,'//','/')
>
> On Mar 9, 2:57 pm, "ciupaz" <luigi.zambe...@gmail.com> wrote:
>
>
>
> > Hi all,
> > I have some strings like these:
>
> > aa/aa//
> > //
> > aa//
> > 4/5/6/7
>
> > I want delete the character "/" when is at the bottom of the string,
> > or the string is only /.
> > So to obtain:
>
> > aa/aa
> > Null
> > aa
> > 4/5/6/7
>
> > How can I get this?
>
> > Thanks a lot.
>
> > Luigi- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Ok, but (my fault) there are some case of
bb/
and I want to obtain
bb


Jack Vamvas

3/9/2007 10:45:00 AM

0

declare @a VARCHAR(10),@b VARCHAR(10)
SET @a = 'aa/aa//'
SET @b = '//'

--------------------example for @---------------------------------
IF RIGHT (@a ,1 ) = '/' SET @a = STUFF(@a,LEN(@a), 1, '')
DECLARE @intCnt1 INT
SET @intCnt1 = 1

WHILE RIGHT (@a ,1 ) = '/'
BEGIN
SET @a = STUFF(@a,LEN(@a) , 1, '')
SET @intCnt1 = @intCnt1 + 1
END



-----------------------example for @b-------------------------------
DECLARE @intCnt INT,@notChar INT
SET @intCnt = 1
SET @notChar = 0
WHILE @intCnt < (LEN(@b) + 1)
BEGIN
IF CHARINDEX( '/' , @b,@intCnt ) = 0 SET @notChar = 1
SET @intCnt = @intCnt + 1
END

IF (@notChar = 0) SET @b = REPLACE(@b,'/','NULL')




PRINT @a

PRINT @b



--

Jack Vamvas
___________________________________
The latest IT jobs - www.ITjobfeed.com
<a href="http://www.itjobfeed.com&q... IT Jobs</a>


"ciupaz" <luigi.zambetti@gmail.com> wrote in message
news:1173434225.496806.119990@q40g2000cwq.googlegroups.com...
> Hi all,
> I have some strings like these:
>
> aa/aa//
> //
> aa//
> 4/5/6/7
>
> I want delete the character "/" when is at the bottom of the string,
> or the string is only /.
> So to obtain:
>
> aa/aa
> Null
> aa
> 4/5/6/7
>
> How can I get this?
>
> Thanks a lot.
>
> Luigi
>


masri999

3/9/2007 11:59:00 AM

0

create table #temp (string varchar(100))
insert into #temp values ('aa/aa//')
insert into #temp values ('//')
insert into #temp values ('aa//')
insert into #temp values ('4/5/6/7')
insert into #temp values ('bb/')
insert into #temp values ('abcd')




select case when
substring(replace(string,'//','/') ,len(replace(string,'//','/')),1 )
= '/'
then substring(replace(string,'//','/'),
1,len(replace(string,'//','/'))-1)
else replace(string,'//','/') end from #temp

drop table #temp


On Mar 9, 3:13 pm, "ciupaz" <luigi.zambe...@gmail.com> wrote:
> On 9 Mar, 11:12, "M A Srinivas" <masri...@gmail.com> wrote:
>
>
>
>
>
> > Try replace (string,'//','/')
>
> > On Mar 9, 2:57 pm, "ciupaz" <luigi.zambe...@gmail.com> wrote:
>
> > > Hi all,
> > > I have some strings like these:
>
> > > aa/aa//
> > > //
> > > aa//
> > > 4/5/6/7
>
> > > I want delete the character "/" when is at the bottom of the string,
> > > or the string is only /.
> > > So to obtain:
>
> > > aa/aa
> > > Null
> > > aa
> > > 4/5/6/7
>
> > > How can I get this?
>
> > > Thanks a lot.
>
> > > Luigi- Nascondi testo tra virgolette -
>
> > - Mostra testo tra virgolette -
>
> Ok, but (my fault) there are some case of
> bb/
> and I want to obtain
> bb- Hide quoted text -
>
> - Show quoted text -