0

let output string will be,

str="01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010"

Some manipulation, *******

Resultant string should be,

"01/Mar/2010,02/Mar/2010<br/>03/Mar/2010,04/Mar/2010<br/>05/Mar/2010"

Here I want to replace Comma (,) by <br/>

Note:

I want to replace even commas only. (before 03/mar/2010 & 05/Mar/2010..like)

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by samaru
0
<?php
$string="your string";
$arr=explode(",",$string)
$newstr="";
$total=count($arr);
for($i=0;$i<$total;$i++)
{
    $newstr.=$arr[$i];
    if($i%2==0)
       $newstr.="<br/>";
    elseif($i<($total-1));
       $newstr.=",";
}
echo $string;
echo $newstr;
?>

Edited by urtrivedi: n/a

0

let output string will be,

str="01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010"

Some manipulation, *******

Resultant string should be,

"01/Mar/2010,02/Mar/2010<br/>03/Mar/2010,04/Mar/2010<br/>05/Mar/2010"

Here I want to replace Comma (,) by <br/>

Note:

I want to replace even commas only. (before 03/mar/2010 & 05/Mar/2010..like)

just simple,
select Replace('01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010', ',','<br />')

0

just simple,
select Replace('01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010', ',','<br />')

I believe he said a <br/> every 2 tokens. The code you posted places it after every token. He's something I quickly whipped up.

DECLARE @dateList AS VARCHAR(1000)
DECLARE @dataItem AS VARCHAR(255)
DECLARE @newList AS VARCHAR(1000)

DECLARE @token AS INT
DECLARE @count AS INT

SELECT @dateList = '01/Mar/2010,02/Mar/2010,03/Mar/2010,04/Mar/2010,05/Mar/2010',
       @dateList = @dateList + ',',
       @count    = 0,
       @newList  = ''

WHILE PATINDEX('%,%', @dateList) <> 0
BEGIN
  
  SELECT  @token = PATINDEX('%,%', @dateList),
          @dataItem = LEFT(@dateList, @token - 1),
          @dateList = STUFF(@dateList, 1, @token, null)

  IF ( @count % 2 ) = 0 AND @count > 0
  BEGIN
    SET @newList = LEFT( @newList, DATALENGTH( @newList ) - 1 ) + '<br/>'
  END  

  SET @count = @count + 1  
  SET @newList = @newList + @dataItem + ',' 
END


PRINT LEFT( @newList, DATALENGTH( @newList ) - 1 )

Edited by samaru: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.