Answers for "java program to insert a string into another string"

12

insert string in string java

String newString = originalString.substring(0, index + 1) 
                           + stringToBeInserted 
                           + originalString.substring(index + 1);
Posted by: Guest on August-20-2020
0

String insertion into another string

// Insert q char c in pos n of the string str.
int strinsert(char **str, char c, int  n, int q)
{
    int len = my_strlen(*str);
    char ins[q + 1];
    char *new = malloc(len + q + 1);

    memset(ins, c, q);
    memset(new, 0, len + q);
    ins[q] = '\0';
    strncpy(new, *str, n);
    new[n] = '\0';
    strcat(new, ins);
    strcat(new, *str + n);
    return (0);
}

strinsert(&str, 'X', strlen(str) / 2, 5);
// Inserting in string str 5 'X' in the middle of the string
Posted by: Guest on November-17-2021

Code answers related to "java program to insert a string into another string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language