OO-Snippets: Iterate over a Sequence

Commons

KeywordsSequence, Sequences, iterate, iteration
LanguageCpp
ApplicationOffice
AuthorsPierre-André Galmes (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHowto iterate over a Sequence ?
Answer

Use the following routine :

Code-Snippet-Listing (snippet-source)

/*  Copyright (C) 2005  - StarXpert - http://www.starxpert.fr */

#include <iostream>
#include <exception>
#include <rtl/ustring.hxx>

#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>

using namespace std;
using namespace ::rtl;


main()
{

[...]

// Get a sequence.
Sequence< ::rtl::OUString > sq = 
rxOfficeServiceManager->getAvailableServiceNames();

// Set some variables on the beginning and the end of the sequence.
rtl::OString aOString;
const ::rtl::OUString* sIterator = sq.getConstArray();
const ::rtl::OUString* sEnd = sIterator + sq.getLength();

// Iterate and display the result.
for ( ; sIterator != sEnd ; ++sIterator)
{
        aOString = ::rtl::OUStringToOString ( *sIterator, RTL_TEXTENCODING_UTF8 );
        cout << "sq : " <<  aOString << endl;
}

}

Changelog

DateUserModification
2005-09-13pagalmesInitial version

and