I want to extract part of a string within given limits in C language. I tried strcpy() but it only extracts the first n characters from a string.
How can I do this?
Asked
Active
Viewed 120 times
-1

bc_wicki
- 1
- 1
-
You can do this by using a simple loop: `for(i=0 ,j = pos ; i
– Robin Halder Feb 28 '15 at 19:43 -
@RobinHalder: but don't forget to show the null termination, and do you need to check that the string is at least as long as the start position of the substring? – Jonathan Leffler Feb 28 '15 at 19:44
-
I am just giving him a view how can he implement that as the question is already answered :) – Robin Halder Feb 28 '15 at 19:45
1 Answers
0
What you are looking for is Substring(). Here's a simple example:
string Str = "I only want to extract \"want\" from this string.";
string Str2 = Str.Substring(7, 4);
MessageBox.Show("String 1: " + Str +" - String 2: "+Str2);
-
Welcome to Stack Overflow. Please read the [About] page soon. Note that this question is tagged [tag:c] and not [tag:c#] or something similar. What you've provided is not using standard C notations. It might be C++, or some other language, but it isn't standard C. I recommend deleting this answer. In the future, be careful to note the tags and the question content (it does say 'C' explicitly), and make sure that your answers fit the questions appropriately. – Jonathan Leffler Feb 28 '15 at 19:42