Replace function

S

Soulless

Hi,

I am tryng to use replace and it is not working. i'm surprised as it
would seem to be a simple method. My code:

foreach (DataRow row in dsSched.Tables["Schedule"].Rows)
{
if (_bStopWork) break;
lsTemp = String.Empty;
lsTemp = row["UpdateSQL"].ToString() +
System.Environment.NewLine;
lsTemp.Replace("S","?");
sb.Append(lsTemp);
}

I am retrieving rows from a dataset to string and the replace is not
replacing the 'S''s like a assume they should.

Any ideas? Thanks!
 
H

Hilton

Try:

sb.Append (lsTemp.Replace ("S", "?");

Alternatively, to correct your code above you need to change the line to:
lsTemp = lsTemp.Replace ("S", "?")

Hilton
 
J

jehugaleahsa

Hi,

I am tryng to use replace and it is not working. i'm surprised as it
would seem to be a simple method. My code:

foreach (DataRow row in dsSched.Tables["Schedule"].Rows)
{
if (_bStopWork) break;
lsTemp = String.Empty;
lsTemp = row["UpdateSQL"].ToString() +
System.Environment.NewLine;
lsTemp.Replace("S","?");
sb.Append(lsTemp);
}

I am retrieving rows from a dataset to string and the replace is not
replacing the 'S''s like a assume they should.

Any ideas? Thanks!

Replace returns the modified string seeing as strings are immutable.
 
L

Lew

Soulless said:
I am tryng to use replace and it is not working. i'm surprised as it
would seem to be a simple method. My code:

foreach (DataRow row in dsSched.Tables["Schedule"].Rows)
{
if (_bStopWork) break;
lsTemp = String.Empty;
lsTemp = row["UpdateSQL"].ToString() +
System.Environment.NewLine;
lsTemp.Replace("S","?");
sb.Append(lsTemp);
}

I am retrieving rows from a dataset to string and the replace is not
replacing the 'S''s like a assume they should.

Replace returns the modified string seeing as strings are immutable.

N.b., the line
lsTemp = String.Empty;

is superfluous.
 
S

Soulless

Soulless said:
I am tryng to use replace and it is not working. i'm surprised as it
would seem to be a simple method. My code:
foreach (DataRow row in dsSched.Tables["Schedule"].Rows)
{
if (_bStopWork) break;
lsTemp = String.Empty;
lsTemp = row["UpdateSQL"].ToString() +
System.Environment.NewLine;
lsTemp.Replace("S","?");
sb.Append(lsTemp);
}
I am retrieving rows from a dataset to string and the replace is not
replacing the 'S''s like a assume they should.
Replace returns the modified string seeing as strings are immutable.

N.b., the line
lsTemp = String.Empty;

is superfluous.

Thanks for the replies!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top