This is a simple function which will read the file line by line and search each individual line until the target string is found, then return the line number it was found in. It will return zero if the string was not found.
This is a simple function whipped up to demonstrate the basic technique, it has not been debugged or tested at all, and is certainly not the best solution possible. It also lacks any form of error trapping/handling.
You should not use this code in any program intended for production without rewriting it.
public function FindStringInFile(byval strTarget as string) as long
Dim iFile as integer 'file number
Dim iLineNum as long 'counter for line number
Dim strTmp as string 'variable length string to hold string from file
Dim bFound as boolean 'flag to indicate it was found
'First, open the file for input:
iFile = freefile 'get the next free file number
open "filename.txt" for input as #iFile 'open the file in input mode
do until eof(ifile) 'continue reading lines until the end of the file
line input #ifile, strTmp 'read a line into the string variable iLineNum = iLineNum + 1 'increment the line number counter
if instr$(strTarget, strTmp) <> 0 then 'set the flag and exit the loop
bFound = true
exit do
end if
loop
'check the flag
if bFound then
'found, return the line number
FindStringInFile = iLineNum
else
'not found, return zero
FindStringInFile = 0
end if
end function
what is string
uitihyiuiphoiphuihyi
Try using Microsoft internet controlin vb. It is in the components list. Its is very easy to use.
give print then select print to file give the file name that file may prn file by
#include<iostream> #include<fstream> #include<vector> #include<string> std::string get_input_file() { while (true) { std::cout << "Enter the input file name: "; std::string filename; std::getline (std::cin, filename); std::ifstream file (filename); if (file.is_open()) { file.close(); return filename; } std::cerr << "The file could not be opened.\n" << std::endl; } } std::string get_search_word() { while (true) { std::cout << "Enter the word to search for: "; std::string search; std::cin >> search; if (search.size()) return search; std::cerr << "The search word cannot be an empty string.\n" << std::endl; } } std::vector<size_t> get_offsets(const std::string& filename, const std::string& search) { std::vector<size_t> offsets; std::ifstream file (filename); if (!file.is_open()) throw std::exception("The file could not be opened."); size_t offset = 0; while (!file.eof()) { size_t pos = 0; char c; while (!file.read(&c, 1).eof() && c!=search[pos]) ++offset; while (pos!=search.size()-1 && !file.read(&c, 1).eof() && c==search[++pos]); if (pos==search.size()-1 && c==search[pos]) offsets.push_back (offset); offset += pos; pos = 0; } file.close(); return offsets; } int main() { std::cout << "Word Search\n" << std::endl; std::string filename = get_input_file(); std::string search = get_search_word(); std::vector<size_t> offsets = get_offsets (filename, search); std::cout << "The word was found " << offsets.size() << " time" << (offsets.size()==1?"":"s") << ".\n" << std::endl; if (offsets.size()) { std::cout << "Offsets:\n"; for (auto off : offsets) std::cout << off << std::endl; } }
gov
The Search Key
what is string
Str converts a number to a string.
uitihyiuiphoiphuihyi
Grep
vb called visual basic where as c the third letter of english alphabet so the basic advantage is the spelling of vb is very large as compared to c although both are bekar language but still attendence demands completion of file n completion of file demands a good friend who helps in writing a file and for helping that friend we have to search such a "goody goody" questions like this so it is the major disadvantage of vb practical over c practical.
.vb
Try using Microsoft internet controlin vb. It is in the components list. Its is very easy to use.
give print then select print to file give the file name that file may prn file by
You will need a PDF server running somewhere that can be accessed by your VB code. It will need to be called from the code through the server and get the PDF file in return. I did that with Tweak PDF Converter, an pdf editor for converting pdf file to word form.
#include<iostream> #include<fstream> #include<vector> #include<string> std::string get_input_file() { while (true) { std::cout << "Enter the input file name: "; std::string filename; std::getline (std::cin, filename); std::ifstream file (filename); if (file.is_open()) { file.close(); return filename; } std::cerr << "The file could not be opened.\n" << std::endl; } } std::string get_search_word() { while (true) { std::cout << "Enter the word to search for: "; std::string search; std::cin >> search; if (search.size()) return search; std::cerr << "The search word cannot be an empty string.\n" << std::endl; } } std::vector<size_t> get_offsets(const std::string& filename, const std::string& search) { std::vector<size_t> offsets; std::ifstream file (filename); if (!file.is_open()) throw std::exception("The file could not be opened."); size_t offset = 0; while (!file.eof()) { size_t pos = 0; char c; while (!file.read(&c, 1).eof() && c!=search[pos]) ++offset; while (pos!=search.size()-1 && !file.read(&c, 1).eof() && c==search[++pos]); if (pos==search.size()-1 && c==search[pos]) offsets.push_back (offset); offset += pos; pos = 0; } file.close(); return offsets; } int main() { std::cout << "Word Search\n" << std::endl; std::string filename = get_input_file(); std::string search = get_search_word(); std::vector<size_t> offsets = get_offsets (filename, search); std::cout << "The word was found " << offsets.size() << " time" << (offsets.size()==1?"":"s") << ".\n" << std::endl; if (offsets.size()) { std::cout << "Offsets:\n"; for (auto off : offsets) std::cout << off << std::endl; } }