Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace SOH character in string

Tags:

string

c#

replace

I am reading a small MSWord document and storing its contents in a string.

There are SOH special characters included in this string. I would like to replace them with a placeholder string, like "#placeholder1" before they are written into a new text (.txt) file. Note that I am not wanting to modify/edit the MSWord document

I'm not sure if string.Replace would suit this or if I need to go a different route. It may just be the parameter I am using for the SOH character.

Suggestions?

like image 285
Ray Alex Avatar asked Sep 16 '25 01:09

Ray Alex


1 Answers

There's no reason why what you're doing shouldn't work. Here's a minimal example that you can test on ideone:

using System;
public class Test
{
    public static void Main()
    {
        String s = "\u0001 This is a test \u0001";
        s = s.Replace("\u0001","Yay!");
        Console.WriteLine(s);
    }
}

The only other thing I can think you might be doing wrong, is not storing the result of your call to Replace.

like image 198
James Holderness Avatar answered Sep 17 '25 15:09

James Holderness