Question : find a substring from a string
Answered by : abdullah-miraz
// CPP program to demonstrate working of string
// find to search a string
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "geeksforgeeks a computer science";
string str1 = "geeks";
// Find first occurrence of "geeks"
size_t found = str.find(str1);
if (found != string::npos)
cout << "First occurrence is " << found << endl;
// Find next occurrence of "geeks". Note here we pass
// "geeks" as C style string.
char arr[] = "geeks";
found = str.find(arr, found+1);
if (found != string::npos)
cout << "Next occurrence is " << found << endl;
return 0;
}
Source : https://www.geeksforgeeks.org/string-find-in-cpp/ | Last Update : Sun, 09 Oct 22
Question : search for substring
Answered by : akintunde-i-makinde
# You can do it in two ways
# 1) Let "grep" read on its standard input
echo "$line" | grep -o select
# 2) tell "grep" here is the string
grep select <<< "$line"
Source : https://unix.stackexchange.com/questions/163810/grep-on-a-variable | Last Update : Wed, 27 Apr 22