Dudearoo
Useing Code::Blocks

Hey Guys! ive got a question, How can you find a string and then print after it??
ive searched google high and low and came out with nothing.
What i want to do is to read a string(StringONE) and see if an other string(StringTWO) is in that string, and if so
then print what i want to do after where stringTWO is.

Please Dont send me links to some website for the find method or so i want YOUR guys Opinion on how to, and please teach me how to Do such a thing.

Thanks you Guys in advance :)

Search for the string.
Add the length of the string to the location found
Start printing.

If you want a better description, give us more information about your situation.

Ok thank you WaltP, my situation is that im scaning a file and pulling each line out and looking for a spicif string what im useing is <!--fakEOF--> and once ive found this string i want, WANT to print after this, please remember that i would love this to be if statment friendly, as im useing while and Do while Loops for this procidure and would like to have all ifstatments catagorized the way i do lots of ifstatments, put them in Voids.

And even better i would like to have it as the string im searching for could be <!--fakEOTag_One--> add a string till <-- fakEOTag_One-end -->
Tell me if that Makes No sence... I tend to do That :)

It makes no sense. We need more technical information you are attempting to use, like C++ strings or C-strings, other constraints you have.

please remember that i would love this to be if statment friendly, as im useing while and Do while Loops for this procidure

What does this mean? It makes no sense.
What is if statement friendly?
What do while and do loops have to do with ifstatments?

and would like to have all ifstatments catagorized the way i do lots of ifstatments, put them in Voids.

What do Voids have to do with anything?
Why/How do you categorize if statements then put them in Voids?
How do you put "ifstatements" in Voids

Is any of this actually germaine to the question? Is it more than simply finding a sequence of characters and printing everything after it?

sorry i kinda went overboard,

Is it more than simply finding a sequence of characters and printing everything after it?

No, its just simple as that, and sorry the if statment and loop thing was some thing that should have stayed in my head, sorry. :)

Let's see if I understand what you want to do.

  1. Search a file.
  2. Find string1 that is followed in the same line by string2
  3. Follow string2 with string3, in the file, written back to disc?

ok. simmiler but diffrent
1. search a file
2.scan that file for avalable opening and closeing tages(ie.fakEOTag_start and fakEOTag_end)
3. (if there is one)between the avalable tags put a string(its contents are not needed to be told, but lets say its name is content), wetween both fakEOTags start and end
4. all in all i want to see in the file, a fakEOTag, with the content string, afterwards the end tag.

--------------------------------------------------------------------------------------
think of it as the paragraph tag for HTML, if that makes sence. :)

thanks for your guys feedback :)

Rather than trying to describe it, which you are doing poorly, show us!

Post a small example of the file (3-4 lines) and exactly what you want printed.

Come to think of it, all you've done is continue trying to describe things. But it also sounds like you know what to do. If you've got it, say "thanks". If not, ask specific questions about what you don't understand.

I think this member is wanting advice on how to insert a string/char* between
two other specified strings/char*.

For example

he reads a html file
looks for first string "<div>"
if found, looks for it's closing tag "</div>", or other specified string

Then insert between those tags/strings

outputting "<div>some string</div>"

That's possible. Its also possible he's trying to find the stuff between the tags. Or even extracting the stuff after the closing tags.

I'm now done guessing and awaiting a clear example of what he wants. From him.

Suzie999 That is exactly what i want, and sorry WaltP for discribing this and now showing, i usually Do and just got lazy, ill spend more time in my posts so the subject will make sence. :)

commented: But you *still* didn't show... Good luck to you. -3

Getting someplace now then.

Next step is to answer the other question that have been asked.
Not least what type of strings are you working with, c type,
c++ std::string?

And perhaps post any code you have tried, even if it does not work.

a C++ string :)

Do you mean this?

string name;

cout << "What is your name? "; 
cin >> name; 
cout << endl; // makes a space after you write your name

cout << "Your name is: " << name << endl;

I just re-read your initial post by the way. Sorry, long day. You can put your characters into a vector, by doing

vector1.push_back(character);

then have another vector and do the same thing for string 2? (you can do a for loop for multiple characters) Then from there use the

find(vector1.begin(), vector1.end(), letter);

algoirthm to find the specific letter(s) that make up a name or something and keep going on until you find your string.

commented: So you're another "VECTORS are the way to do everything" programmer. Remember, vectors are more advanced than arrays. Anyone that cna use vectors can to the basics. +0

ok...... ive kinda got it, first find the string, and then insert after.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
    int six = 6;
    string div = "DIV=";
    string locator;
    string varable = "hey1234";
    size_t founditzz;
    //-------------------------------
    fstream filesave;
    filesave.open("Some site.HTML");
    while (filesave.good())
    {
    filesave >> locator;
    cout << locator << endl;
    div.insert(4,varable);
    cout << div << endl;
    // .HTML because this is the file format i want to use this method with.
    ofstream filesave2;
    filesave2.open("Some site.HTML");
    filesave2 << div;
    filesave2.close();
    ifstream load;
    load.open("Some site.HTML");
    load >> locator;
    founditzz=locator.find(div);
    load.close();
    }
    filesave.close();
    return 0;
}

This works if you know the amount of charaters before the "=" but i want to make this easier in the long run by knowing now, how can i do this without knowing the amount of charaters?

You have this line in your code

founditzz=locator.find(div);

Do you know why you put it there and what that function returns?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.