How can I pass String.concat "/" [""; "Usr"; "local"; "Bin"] for c?

1

I know a lot of things in c, however, this is new to me, but, see below with OCaml: Generating a component filename: Note that the second argument is a list of strings.

  
  • String.concat "/" [""; "usr"; "local"; "bin"]
  •   

It's very simple and easy to use. This generates as output ....

  
  • : string="/ usr / local / bin"
  •   

How can I pass this to c? I would like to understand how to do this in c!

I wanted to use this with: document.write () with a printf.

Steps:

The program inserts:

  
  • String.concat "/" [""; "usr"; "local"; "bin"]
  •   

Generates:

  
  • : string="/ usr / local / bin"
  •   

And then give one:

  
  • document.write ()
  •   

And then transform:

  
  • document.write ("/ usr / local / bin");
  •   

Then in:

  
  • printf.
  •   

What do I want with this?

  
  • I want to create a directory! And so insert files or data into this directory!
  •   

Because document.write (); ?

  
  • I want to insert this directory into the document and reference it.
  •   

Why printf?

  
  • Because printf does a real document.write (), writing to data file.
  •   
    
asked by anonymous 23.08.2017 / 16:58

1 answer

0

This is a solution without many validations:

#include <string>
#include <vector>
#include <numeric>
using namespace std;


class String
{
public:
    string concat ( const string val)
    {
        vector _tokens;
        string delimiters(" \"\';[]"); 

        Tokenize ( string(val), _tokens, delimiters);
        vector::iterator iv = _tokens.begin();

        for(int i=2; i < _tokens.size(); i++)
        {
            _tokens[i] = _tokens[0] + _tokens[i];
        }

        return accumulate(_tokens.begin(), _tokens.end(), string(""));;
    }

private:
    void Tokenize(const string & str,
                  vector & tokens,
                  const string & delimiters = " ")
    {
        // Skip delimiters at beginning.
        string::size_type lastPos = str.find_first_not_of(delimiters, 0);
        // Find first "non-delimiter".
        string::size_type pos     = str.find_first_of(delimiters, lastPos);

        while (string::npos != pos || string::npos != lastPos)
        {
            // Found a token, add it to the vector.
            tokens.push_back(str.substr(lastPos, pos - lastPos));
            // Skip delimiters.  Note the "not_of"
            lastPos = str.find_first_not_of(delimiters, pos);
            // Find next "non-delimiter"
            pos = str.find_first_of(delimiters, lastPos);
        }
    }
};

int main(int argc, _TCHAR* argv[])
{
    String MyString;

    string path = MyString.concat("\"/\" [\"\"; \"usr\"; \"local\"; \"bin\"]" );

    return 0;
}

    
23.08.2017 / 22:14