Replace All Occurrences Of A Substring In A String With Another Substring | C Programming Example

Replace All Occurrences Of A Substring In A String With Another Substring | C Programming Example

Portfolio Courses

2 года назад

13,057 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Edwin Villarroel
Edwin Villarroel - 19.10.2023 09:17

you are so dashing and handsome

Ответить
grunger
grunger - 04.09.2023 08:52

Can this be done with a dynamic array and user-entered strings? Im a c++ student just started recently Edit: Professor wants us to use c-string

Ответить
drig7
drig7 - 07.05.2023 16:57

another way to count the occurences of your substring is this:
although it uses another temporary char array.

char str[]="the cat chased the mouse"
char sub[] = "the"
char temp[strlen(sub)];
strcpy(temp, str);

int occurence=0;
while( strstr(temp, sub) != NULL)
{
occurence++;
strcpy( temp, strstr(temp, sub) + strlen(sub) );
}

//char original string (str) is being copied to temp array, then the temp array is being checked if it contains the substring, if it does it increments occurence and then overwrites the temp array EXCLUDING the found substring and repeats.

Ответить
Oghenemaro Erivona
Oghenemaro Erivona - 01.11.2022 14:03

AMAZING Walk through

Ответить
sarbudeen kather
sarbudeen kather - 07.04.2022 11:20

nice explanation keep code for as

Ответить
vishavjeet sharma
vishavjeet sharma - 22.01.2022 20:43

Excellent explanation 👌👌

Ответить
Mongraal
Mongraal - 07.01.2022 20:08

Congrats bro for 1k subs!!🤟

Ответить