Tag: Strings

  • Finding permutations in strings

    In C++ the Standard Template Library provides us with std::next_permutation to easily implement this.

    #include <iostream>
    #include <algorithm>
    #include <iterator>
    #include <string.h>
      
    int main()
    {
        char str[] = "abcd";
        const size_t len = strlen( str );
      
        do
        {
            std::copy( str,
            str + len,
            std::ostream_iterator<char>( std::cout ) );
            std::cout << std::endl;
        }
        while ( std::next_permutation( str, str + len ) );
    
    	return 0;
    }
    

    (more…)

  • Java Strings: The Basics

    One long section of code outlining how to achieve some basic string handling objectives in Java. Currently trying to get to grips with this language after spending far too many years concentrating on C++. Each technique is demonstrated with a code snippet. As with a lot of my other stuff, any new stuff I find useful will get added at a later date:
    (more…)