i need to find a substring in a string and get the next 3 characters
for example
010100 this is the string the substring is 010 i need to search for this substring and i also need to return the next 3 characters i.e 100. i need to apply this for this string 01010000001001100000100010 is this possible somehow ? |
Quote:
|
oh ok... ill check that out .. is it possible in c++ ?
|
Certainly
|
Quote:
|
You may also need to consider all your output options here too:
eg. your first string '010100' contains the characters 010 twice. Also, what if you encounter 010 but there are not 3 characters after (ie 01011). Do you retrun just the 2 characters, do you pad the last character (if so, with what) or do you simply ignore this scenario as invalid as not 3 characters. Just a thought btw. these considerations are irrelevant of language or program used |
@grail i considered that .. the string that im going to input into this program is going to be of a proper form
|
Hi, most languages (and I'm thinking Ruby and Python) have a String class that contains methods that let you search for substrings. The result of these methods is usually the index (the position) of the first character within the string. Using this position + the length of the searched substring you can find the start position of the following 3 characters.
the string "supercalifragilisticexpialidocious" is just a list or characters in an array Code:
supercalifragilisticexpialidocious I'm not sure if C++ has a String class but I'm fairly confident that there will be methods that will find the position of a substring within a longer string; no idea what they are though. Hope this was a little bit helpful. |
Code:
man string Code:
man strstr |
All times are GMT -5. The time now is 12:13 AM. |