Share via

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 | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

  1. LesHay 7,146 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.