Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Deleting data in a string using offset

Posted on 1998-06-13
2
Medium Priority
?
170 Views
Last Modified: 2010-04-01
I have a string and a offset for that string, e.g.
string : “c:\dir1\dir2\file.ext”
offset : 13
and now i want to delete everything which is left from the offset. that only file.ext stays.
how can i do that ???
0
Comment
Question by:sbartok
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 0 total points
ID: 1165828
copy the information forwards within the string, like

strcpy(string,string+13);
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165829
Note technically this has a problem.  The two strings specified to strcpy should not overlap.  But it shouldn't be a problem when shifting forwards.  When shifting backwards it could be a problem.  You can use memmove() or a seperate string buffer if you want to be really safe.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question