I only have access to "C" and you need to replace the characters in the character array. I have not come up with any simple solutions for this relatively simple procedure.
I was given an array of characters, for example:
char strBuffer[] = "/html/scorm12/course/course_index.jsp?user_id=100000232&course_id=100000879&course_prefix=ACQ&version=2&scorm_version=3&roster_id=100011365&course_name=Test%20Course%201.2&mode=browse&course_number=0000&mode_id=1";
I need to change this buffer to replace everything &with &. The resulting buffer should not overwrite strBuffer (you can create a new buffer).
Any suggestions?
Edit:
In the past, I ran the strstr function in a loop, but searched for a simpler solution, possibly C, equivalent to the String.Replace method.
Edit:
For my immediate needs I need everything I need.
char strBuffer[] = "/html/scorm12/course/course_index.jsp?user_id=100000232&course_id=100000879&course_prefix=ACQ&version=2&scorm_version=3&roster_id=100011365&course_name=Test%20Course%201.2&mode=browse&course_number=0000&mode_id=1";
char strTemp[1024];
char *s = (char*)strBuffer;
int i=0;
while (*s)
{
strTemp[i++] = *s;
if (strncmp(s,"&",5) == 0)
{
s += 5;
}
else
s++;
}
strTemp[i] = 0;
Future changes:
- Create a utility function to save this function.
- Pass the search string as a parameter.
- Define the length of the search bar so that you can remove hardcoded 5.
- strTemp.
- .
EDIT:
, :
http://www.solutionmaniacs.com/blog/2012/11/25/c-removereplace-characters-in-a-string.html