How do I add a string after the last backslash in another string c++











up vote
-3
down vote

favorite












So I would like to be able to add a string after the last backslash of a string



Example:



string1 = C:UsersAdminOneDriveDesktopText File.txt

string2 = "My"


I want to add string2 after the last backslash of string1



result = C:UsersAdminOneDriveDesktopMy Text File.txt
^









share|improve this question




















  • 8




    What have you tried so far?
    – Yksisarvinen
    Nov 9 at 13:17










  • @Yksisarvinen Nothing So far :(
    – Matin Plays
    Nov 9 at 13:19










  • So please consider reading this
    – Ayak973
    Nov 9 at 13:21










  • if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
    – dlatikay
    Nov 9 at 13:24








  • 1




    Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
    – Nox
    Nov 9 at 13:27















up vote
-3
down vote

favorite












So I would like to be able to add a string after the last backslash of a string



Example:



string1 = C:UsersAdminOneDriveDesktopText File.txt

string2 = "My"


I want to add string2 after the last backslash of string1



result = C:UsersAdminOneDriveDesktopMy Text File.txt
^









share|improve this question




















  • 8




    What have you tried so far?
    – Yksisarvinen
    Nov 9 at 13:17










  • @Yksisarvinen Nothing So far :(
    – Matin Plays
    Nov 9 at 13:19










  • So please consider reading this
    – Ayak973
    Nov 9 at 13:21










  • if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
    – dlatikay
    Nov 9 at 13:24








  • 1




    Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
    – Nox
    Nov 9 at 13:27













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











So I would like to be able to add a string after the last backslash of a string



Example:



string1 = C:UsersAdminOneDriveDesktopText File.txt

string2 = "My"


I want to add string2 after the last backslash of string1



result = C:UsersAdminOneDriveDesktopMy Text File.txt
^









share|improve this question















So I would like to be able to add a string after the last backslash of a string



Example:



string1 = C:UsersAdminOneDriveDesktopText File.txt

string2 = "My"


I want to add string2 after the last backslash of string1



result = C:UsersAdminOneDriveDesktopMy Text File.txt
^






c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 14:38









Rhathin

5391313




5391313










asked Nov 9 at 13:16









Matin Plays

51




51








  • 8




    What have you tried so far?
    – Yksisarvinen
    Nov 9 at 13:17










  • @Yksisarvinen Nothing So far :(
    – Matin Plays
    Nov 9 at 13:19










  • So please consider reading this
    – Ayak973
    Nov 9 at 13:21










  • if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
    – dlatikay
    Nov 9 at 13:24








  • 1




    Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
    – Nox
    Nov 9 at 13:27














  • 8




    What have you tried so far?
    – Yksisarvinen
    Nov 9 at 13:17










  • @Yksisarvinen Nothing So far :(
    – Matin Plays
    Nov 9 at 13:19










  • So please consider reading this
    – Ayak973
    Nov 9 at 13:21










  • if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
    – dlatikay
    Nov 9 at 13:24








  • 1




    Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
    – Nox
    Nov 9 at 13:27








8




8




What have you tried so far?
– Yksisarvinen
Nov 9 at 13:17




What have you tried so far?
– Yksisarvinen
Nov 9 at 13:17












@Yksisarvinen Nothing So far :(
– Matin Plays
Nov 9 at 13:19




@Yksisarvinen Nothing So far :(
– Matin Plays
Nov 9 at 13:19












So please consider reading this
– Ayak973
Nov 9 at 13:21




So please consider reading this
– Ayak973
Nov 9 at 13:21












if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
– dlatikay
Nov 9 at 13:24






if this is specifically about strings that are file system paths, consider using filesystem related library functions of the runtime environment of whatever operating system you are coding for. with portability in mind, you would for example split by or / this is best left to FS abstraction.
– dlatikay
Nov 9 at 13:24






1




1




Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
– Nox
Nov 9 at 13:27




Or even better, to avoid any dependency, if you can use c++17: en.cppreference.com/w/cpp/filesystem (see what I did here @YSC)
– Nox
Nov 9 at 13:27












1 Answer
1






active

oldest

votes

















up vote
3
down vote













Have a look at those two functions from std::string




  • std::string::find_last_of

  • std::string::insert


Please next time tho, consider reading this article about how to ask a question on SO :)






share|improve this answer



















  • 1




    Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
    – YSC
    Nov 9 at 13:21












  • Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
    – Nox
    Nov 9 at 13:25










  • Nobody's perfect :D
    – YSC
    Nov 9 at 13:27






  • 1




    Have you actually read those two links? There will also give you example on how to use those functions
    – Nox
    Nov 9 at 13:42






  • 1




    @MatinPlays "Can you give me an example in code" SO is not a free code writing service.
    – Slava
    Nov 9 at 13:53













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226436%2fhow-do-i-add-a-string-after-the-last-backslash-in-another-string-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













Have a look at those two functions from std::string




  • std::string::find_last_of

  • std::string::insert


Please next time tho, consider reading this article about how to ask a question on SO :)






share|improve this answer



















  • 1




    Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
    – YSC
    Nov 9 at 13:21












  • Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
    – Nox
    Nov 9 at 13:25










  • Nobody's perfect :D
    – YSC
    Nov 9 at 13:27






  • 1




    Have you actually read those two links? There will also give you example on how to use those functions
    – Nox
    Nov 9 at 13:42






  • 1




    @MatinPlays "Can you give me an example in code" SO is not a free code writing service.
    – Slava
    Nov 9 at 13:53

















up vote
3
down vote













Have a look at those two functions from std::string




  • std::string::find_last_of

  • std::string::insert


Please next time tho, consider reading this article about how to ask a question on SO :)






share|improve this answer



















  • 1




    Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
    – YSC
    Nov 9 at 13:21












  • Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
    – Nox
    Nov 9 at 13:25










  • Nobody's perfect :D
    – YSC
    Nov 9 at 13:27






  • 1




    Have you actually read those two links? There will also give you example on how to use those functions
    – Nox
    Nov 9 at 13:42






  • 1




    @MatinPlays "Can you give me an example in code" SO is not a free code writing service.
    – Slava
    Nov 9 at 13:53















up vote
3
down vote










up vote
3
down vote









Have a look at those two functions from std::string




  • std::string::find_last_of

  • std::string::insert


Please next time tho, consider reading this article about how to ask a question on SO :)






share|improve this answer














Have a look at those two functions from std::string




  • std::string::find_last_of

  • std::string::insert


Please next time tho, consider reading this article about how to ask a question on SO :)







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 13:22

























answered Nov 9 at 13:20









Nox

6451621




6451621








  • 1




    Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
    – YSC
    Nov 9 at 13:21












  • Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
    – Nox
    Nov 9 at 13:25










  • Nobody's perfect :D
    – YSC
    Nov 9 at 13:27






  • 1




    Have you actually read those two links? There will also give you example on how to use those functions
    – Nox
    Nov 9 at 13:42






  • 1




    @MatinPlays "Can you give me an example in code" SO is not a free code writing service.
    – Slava
    Nov 9 at 13:53
















  • 1




    Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
    – YSC
    Nov 9 at 13:21












  • Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
    – Nox
    Nov 9 at 13:25










  • Nobody's perfect :D
    – YSC
    Nov 9 at 13:27






  • 1




    Have you actually read those two links? There will also give you example on how to use those functions
    – Nox
    Nov 9 at 13:42






  • 1




    @MatinPlays "Can you give me an example in code" SO is not a free code writing service.
    – Slava
    Nov 9 at 13:53










1




1




Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
– YSC
Nov 9 at 13:21






Beat me by a second. I'd would have provided better links though, cplusplus.com is terrible. Try cppreference.com instead ;).
– YSC
Nov 9 at 13:21














Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
– Nox
Nov 9 at 13:25




Haha, yeah I know, you're not the only one, but believe or not, I do prefere cplusplus.com :)
– Nox
Nov 9 at 13:25












Nobody's perfect :D
– YSC
Nov 9 at 13:27




Nobody's perfect :D
– YSC
Nov 9 at 13:27




1




1




Have you actually read those two links? There will also give you example on how to use those functions
– Nox
Nov 9 at 13:42




Have you actually read those two links? There will also give you example on how to use those functions
– Nox
Nov 9 at 13:42




1




1




@MatinPlays "Can you give me an example in code" SO is not a free code writing service.
– Slava
Nov 9 at 13:53






@MatinPlays "Can you give me an example in code" SO is not a free code writing service.
– Slava
Nov 9 at 13:53




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226436%2fhow-do-i-add-a-string-after-the-last-backslash-in-another-string-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff