Terry Light
Terry Light

Reputation: 109

How to find a string in a txt file with case insensitivity and still retain part capitalization? In C++

It would be easy to make everything in the file lowercase and find it, but I want to find the string with the original capitalization so I could put it to a pointer and print it later. For example FIND_WORD ransom. File Word found. Line added DISPLAY rAnSoM nOtE. yOu HaVe TiLl nOon.

Upvotes: 0

Views: 165

Answers (1)

David Schwartz
David Schwartz

Reputation: 182819

Go through the file line by line. For each line, go through the string from beginning to end.

For each starting point in the line, do a case-insensitive compare of the subsequent characters in the string to the characters in the word you're trying to find. If they all match, output that entire line as originally read.

In other words, don't convert anything to lower case. Instead, do a case-insensitive compare.

Upvotes: 1

Related Questions