Replace Char

S-Soft 666 Reputation points
2023-01-17T13:46:33.9933333+00:00

Hello

I need to inset an string to an html page, so need to replace new line with <brr> in my input string:

My input string can have either char(10) only, char(13) only and/or char(13) + char(10) both together.

So first should replace char(13) + char(10) combinations, then if any single char(13) or char(10) remains, replace them too.

Is this code what I need?

InputString.Replace(New Char() {Convert.ToChar(13), Convert.ToChar(10)}, "<br>")

Seems not working on some cases, I don't know what this part does:

New Char() {Convert.ToChar(13), Convert.ToChar(10)}

Thanks for advise :)

Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,141 Reputation points
    2023-01-17T14:36:33.2166667+00:00

    Hi

    Maybe this would work.

        Dim test As String = "abcDEF" & vbCr & "ABCDefg" & vbLf & "WERTY" & vbCrLf & "YTRE" & "abcDEF" & vbCr & "ABCDefg" & vbLf & "WERTY" & vbCrLf & "YTRE"
        'abcDEF
        'ABCDefg
        'WERTY
        'YTREabcDEF
        'ABCDefg
        'WERTY
        'YTRE
    
    
        Dim res As String = test.Replace(vbCrLf, " < br > ").Replace(vbLf, " < br > ").Replace(vbCr, " < br > ")
    
        'abcDEF < br > ABCDefg < br > WERTY < br > YTREabcDEF < br > ABCDefg < br > WERTY < br > YTRE
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.