Replace To " " does not wat i expected

  • Thread starter Thread starter Stijn VA
  • Start date Start date
S

Stijn VA

Okee, the story goes like this:

I have a string that can not contain spaces (It is retrieved from a
externat application...)

At first they replaced the spaces by '_' so somthing like "ABC DEF"
would be saved as "ABC_DEF".
All we did was something like:
str = str.Replace("_"," ");
 
Okee, the story goes like this:

I have a string that can not contain spaces (It is retrieved from a
externat application...)

At first they replaced the spaces by '_' so somthing like "ABC DEF"
would be saved as "ABC_DEF".
All we did was something like:
str = str.Replace("_"," ");

-- I hitted the "Submit button by accedent --

Okee, the story goes like this:

I have a string that can not contain spaces (It is retrieved from a
externat application...)


At first they replaced the spaces by '_' so somthing like "ABC DEF"
would be saved as "ABC_DEF".
All we did was something like:

str = str.Replace("_"," ");

So far,so good...

But then I needed to store a '_' in the string....
So we decided to replace the spaces by somthing less common: "%SPACE%"

You think it would by simply
str = str.Replace("%SPACE%", " ");

But: "ABC%SPACE%DEF" result in : "ABCDEF"

Someone any idee?
 
So we decided to replace the spaces by somthing less common: "%SPACE%"

You think it would by simply
str = str.Replace("%SPACE%", " ");

But: "ABC%SPACE%DEF" result in : "ABCDEF"

Someone any idee?

Sounds unlikely.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Stijn VA said:
You think it would by simply
str = str.Replace("%SPACE%", " ");

But: "ABC%SPACE%DEF" result in : "ABCDEF"

Someone any idee?
Can't confirm it. I tried following code:

using System;

class A
{
static void Main()
{
string str = "ABC%SPACE%DEF";
str = str.Replace("%SPACE%", " ");
Console.WriteLine(str);
}
}

and it printed "ABC DEF".

Did you check the value in the debugger directly before and after the
replace? Maybe the space got lost somewhere else.

Christof
 
Can't confirm it. I tried following code:

using System;

class A
{
static void Main()
{
string str = "ABC%SPACE%DEF";
str = str.Replace("%SPACE%", " ");
Console.WriteLine(str);
}

}

and it printed "ABC DEF".

Did you check the value in the debugger directly before and after the
replace? Maybe the space got lost somewhere else.

Christof

Okee, maybe I lose is some where else. I used it in a dll called by an
BizTalk orchestration, I write the string to the event log.. and there
I 'm missing it. And this line was the only thing that has been
chanced...
But if it isn't the replace function, than it shall be something
else...
 
FYI

At some point a Batch file was executed to insert the string in the
external app...
So it went looking for an envinment variable %SPACE%, and replaced it
with it value (wich was nothing, because it does not exist....)
 

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

Back
Top