Code in VC++.NET

I have a string that has html tags. I want to replace <BR> with \n, but not sure if <BR> will be uppercase, lowercase, or a mixture of both. The string replace function allows only one parameter for the replaced value. Is there a better way of doing this than checking 4 times? I will display the string in a button. Thanks.

Example:
string = one<BR>two<br>three

str =string->Replace ("<BR>", S"\n");
str =string->Replace ("<br>", S"\n");
str =string->Replace ("<Br>", S"\n");
str =string->Replace ("<bR>", S"\n");

or

str =string->ToUpper()->Replace ("<BR>", S"\n");
but I do not want to make the string all upper or lower case.

I would probably make a duplicate copy of the string, convert it to all upper (or lower) case. Then instead of using the Replace method you show, find the position of the first occurrence of "<BR>" then replace it in both copies of the string. I don't have enough experience with VC++.NET to show an example. But that class probably has a find function that returns the starting position of a substring.

or you could write your own function that will do case-insensitive search and replaces.

Sugestion: Use regex, produces just about the fastest searches possible (you need a external library thought, I doubt it comes included in vc++ atleast I havent seen it, boost.org is one good source).

In C you can use stricmp() (or _stricmp() with the Microsoft compilers). Or you can write your own function, as Ancient Dragon suggested.

I got it using Regex.

Example:
string = one<BR>two<br>three

str =string->Replace ("<BR>", S"\n");
str =string->Replace ("<br>", S"\n");
str =string->Replace ("<Br>", S"\n");
str =string->Replace ("<bR>", S"\n");

Solution:
str = Regex::Replace (str, S"<[Bb][Rr]>", S"\n");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.