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
^
c++
add a comment |
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
^
c++
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
add a comment |
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
^
c++
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++
c++
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
add a comment |
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
add a comment |
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 :)
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
|
show 1 more comment
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 :)
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
|
show 1 more comment
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 :)
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
|
show 1 more comment
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 :)
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 :)
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
|
show 1 more comment
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
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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