locked
Does anyone know the char equivalent of pipe? | RRS feed

  • Question

  • User64294366 posted

    I needed to perform some filtering on large delimited files. I loaded the files into a sql table, performed the data manipulation and then exported the files as | delimited. The original files had field separators as delimiters which in C# are (char)(28). The delimiters appear as FS in Notepad++.  Now I am trying to convert the pipe back to the Field Separators but have not been able to find the equivalent in a char format. I tried line.Replace as show in the code below, but I end up with the pipes anyway.

    Can anyone help?

    Thanks,


    Char c = new Char();
    c=(char)(28); //Field Separator
    string line="";
    using (StreamReader inputBundleFile = new StreamReader(@"c:\RKISET\PU401650922_New.RKI")) { while ((line = inputBundleFile.ReadLine()) != null) { line.Replace(Convert.ToChar("|"), c); sb.Append(line); sb.Append("\r\n"); Console.WriteLine("Line Added"); } } using (StreamWriter outfile = new StreamWriter(@"c:\RKISET1\PU401650922_New.RKI")) { outfile.Write(sb); }

    Thursday, September 24, 2015 12:42 PM

Answers

  • User281315223 posted

    It's important to remember that the Replace() method doesn't work inline, it actually returns a string with the replacement already performed, so you need to update your line as such :

    line = line.Replace("|", c);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 24, 2015 12:45 PM

All replies

  • User281315223 posted

    It's important to remember that the Replace() method doesn't work inline, it actually returns a string with the replacement already performed, so you need to update your line as such :

    line = line.Replace("|", c);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 24, 2015 12:45 PM
  • User64294366 posted

    Somebody needs to slap me on the back of the head.

    Thanks, that did it.

    Thursday, September 24, 2015 12:49 PM