Marco
Marco

Reputation: 1025

How to search a string within another string in Visual C++?

I want to need to find a string, replace the string by another string.

For example, replace 'apple' to 'orange' in the following string.

"I love apple"

What function should I use?

Thanks

Upvotes: 0

Views: 1581

Answers (1)

David Yaw
David Yaw

Reputation: 27864

Since this question is tagged C++/CLI, I'm assuming you're referring to managed String objects.

If so, then there's a Replace method on the String class you can use.

String^ orig = "I love apple";
String^ modified = orig->Replace("apple", "orange");

Upvotes: 1

Related Questions