C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problème avec std::string::find_first_not_of

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Michaël Delva
Guest





PostPosted: Thu Mar 04, 2004 4:11 pm    Post subject: Problème avec std::string::find_first_not_of Reply with quote



Bonjour à tous,

Je voudrais dans mon programme créer des "raccourcis" dans les chemins de
mes fichiers. Ex:

mon programme se trouve ici: "C:Program FilesMonAppapp.exe"
il me donne ceci: "$(MonApp)app.exe"

si un fichier se trouve sur un CDROM "D:fichier.txt"
il me donne ceci: "$(CDROM)fichier.txt"

Ceci afin de ne pas écrire en dur les chemins de mes fichiers, et que je
puisse "porter" le programme sur d'autres machines sans devoir tout
modifier.

Bref, j'arrive pour l'instant à modifier un chemin pour qu'il me prenne
en compte les raccourcis.

Mais détecter les raccourcis et réécrire le chemin me pose problème, du
moins pour le CD-ROM.

Si je lui passe ça: "$(MVS)\Stats\", il me donne bien "C:Program Files
MVSStats"

Par contre si je lui passe ça: "$(CDROM)\Stats\", il me donne
"C:Program FilesMVS(CDROM)Stats"


Voici la fonction:

//-----------------------------------------------------------------------
AnsiString __fastcall Load_Path(const AnsiString & path)
{
std::string old_path = path.c_str();

std::string::size_type begin = 0,
racc_app = 0,
racc_cd = 0;

//S'il ne trouve pas de raccourci, il retourne le path d'entrée
std::string new_path = old_path;

//Les variables
const std::string path_application = "C:\Program Files\MVS\";
const std::string path_CD = "D:\";
const std::string raccourci_MVS = "$(MVS)\";
const std::string raccourci_CDROM = "$(CDROM)\";

//On cherche le raccourci de l'application
racc_app = old_path.find_first_not_of(raccourci_MVS,begin);
//On cherche le raccourci du CDROM
racc_cd = old_path.find_first_not_of(raccourci_CDROM,begin);

if (racc_app != begin)
new_path = old_path.replace(begin,racc_app-1,path_application);
else if (racc_cd != begin)
new_path = old_path.replace(begin,racc_cd-1,path_CD);

return new_path.c_str();
}
//-----------------------------------------------------------------------

Vous voyez d'où ça peut venir?

Merci d'avance!
Back to top
Michaël Delva
Guest





PostPosted: Thu Mar 04, 2004 4:38 pm    Post subject: Re: Problème avec std::string::find_first_not_of Reply with quote



Bon, ben je viens de trouver:

AnsiString new_path;

racc = old_path.find(raccourci_MVS,begin);
racc_cd = old_path.find(raccourci_CDROM,begin);

if (racc == begin)
new_path = old_path.replace(begin,raccourci_MVS.size
(),path_application).c_str();
else if (racc_cd == begin)
new_path = old_path.replace(begin,raccourci_CDROM.size
(),path_CD).c_str();

fonctionne bien...

Désolé d'avoir posté pour rien!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.