Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Replace To " " does not wat i expected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stijn VA - 15 Jun 2007 10:25 GMT
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("_"," ");
Stijn VA - 15 Jun 2007 10:29 GMT
> Okee, the story goes like this:
>
[quoted text clipped - 5 lines]
> 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?
Jon Skeet [C# MVP] - 15 Jun 2007 10:36 GMT
<snip>

> So we decided to replace the spaces by somthing less common: "%SPACE%"
>
[quoted text clipped - 4 lines]
>
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Christof Nordiek - 15 Jun 2007 10:50 GMT
> 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
Stijn VA - 15 Jun 2007 11:26 GMT
> > You think it would by simply
> > str = str.Replace("%SPACE%", " ");
[quoted text clipped - 24 lines]
>
> 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...
Stijn VA - 15 Jun 2007 11:42 GMT
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....)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.