Replace Strings

I saw that I can’t use String.Replace(string, string).
Can anyone suggest on a way to implement it easily?

Hi ami. Hope this helps.

I think it’s very helpfull :wink:

Many string functions available at

You can download library, or just take the code you want.

  • StringBuilder (Implemented as stand alone class)
  • string.Replace (Extension method on string object)
  • StringUtility.Format (Implemented as a static method on StringUtility)
  • StringUtility.IsNullOrEmpty (Implemented as a static method on StringUtility)
  • Parse.TryParseInt (Short/Long…) (Implemented as a static method on Parse)

Since I first needed the Join and Split functionality I could implement a String.Replace like this:

public static string Replace(this string s, string oldValue, string newValue, bool ignoreCase = false)
    return s.Split(oldValue, ignoreCase).Join(newValue); 

You can find the Join / Split / Replace extension methods on my blog at

hey, i was looking to use the stringbuilder in my app to save myself from adding strings together manually, but im a little unsure of how to add this to my project, i added the DLL as a reference and it allowed me to see the stringbuilder class and reference in my code but i get an error when building the project. i am pretty sure i am adding it to the project incorrectly, how am i supposed to add it?

Do you have the be & le directories intact?

yeah, but the folder structure isnt one i know what to do with, there are the dll (that i added in as a reference), but there are the be and le folders that also contain a dll (named the same). there are also the .pdbx and .pe files with the same names. what do i need to do?

you should have a folder structure like

   -   MyAssembly.dll               [b]<<<----  Add this one as reference[/b]
   -   MyAssembly.pdb
   -   be
      -   MyAssembly.dll           (Optional)
      -   MyAssembly.pdb         (Optional)
      -   MyAssembly.pdbx
   -   le
      -   MyAssembly.dll          (Optional)
      -   MyAssembly.pdb        (Optional)
      -   MyAssembly.pdbx

The .pdb files are optional.

BTW if it helps, you can now find the extensions in nuget, search for netmfcommonext.

ok, so what you are saying is take that folder i was given (that contains the dll’s and the le and be folders) and add the root dll file as a reference? do i need to add the whole folder to my project or just add the correct reference dll? why are there several versions of what appears to be the same dll? and what do the le and be stand for exactly?

Pretty much, I updated the post above with the bits you can do without

be = big endian
le = little endian

Add like this: - YouTube
Or via nuget like this: - YouTube

ok, then maybe you can explain something. it didnt work when i took the dll out by itself, but when i added it as a reference while it was in the folders it did work. this makes me think that the dll itself needs the external files. but wouldnt it have been much cleaner to just have all the stuff in that one DLL? why make the files so they need to reference extenal parts?

you might find that all the deployment tools figure out whether you have a LE or BE device and deploy the correct DLL to you. The “top level” DLL may not really be the DLL that gets used, but a “holder”. Anyway, whatever the reason, now you know what to do next time.

I think the DLL is only there to make Visual Studio intellisense work, the actual code is in the .pe files.

I can’t find the “string replace” from the link. Can you tell me how cam I get your “string replace”.

I have checked your blog link, but I didn’t find the methods, can you tell me where are the metheds?

A function from works great.

public static string Replace(this string content, string find, string replace)
            int startFrom = 0;
            int findItemLength = find.Length;

            int firstFound = content.IndexOf(find, startFrom);
            StringBuilder returning = new StringBuilder();

            string workingString = content;

            while ((firstFound = workingString.IndexOf(find, startFrom)) >= 0)
                returning.Append(workingString.Substring(0, firstFound));

                // the remaining part of the string.
                workingString = workingString.Substring(firstFound + findItemLength, workingString.Length - (firstFound + findItemLength));


            return returning.ToString();