I'm trying to convert this VBA fonction that remove CRLF from string to a C# function that must do the same result
Private Function RemoveCRLFFromString(ByVal pString As Variant) As String
Dim i As Integer
Dim c As String * 1
If IsNull(pString) Then
RemoveCRLFFromString = ""
Else
For i = 1 To Len(pString)
c = Mid$(pString, i, 1)
If Asc(c) <> 10 And _
Asc(c) <> 13 Then
RemoveCRLFFromString = RemoveCRLFFromString & c
End If
Next i
End If
RemoveCRLFFromString = Left$(RemoveCRLFFromString, 9)
End Function
So far I have come up with:
public static string RemoveCRLFFromString(string pString )
{
if(String.IsNullOrEmpty(pString))
{
return pString ;
}
string lineSep = ((char) 0x2028).ToString();
string paragraphSep = ((char)0x2029).ToString();
return pString.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty).Replace(lineSep, string.Empty).Replace(paragraphSep, string.Empty);
}
But it's not achieving the same result, can someone help me adjust my C# function to match the same result as the VBA version?