Cách chèn một chuỗi vào một chuỗi khác C++
Ngày đăng:
22/12/2022
Trả lời:
0
Lượt xem:
155
Sự miêu tảIf a string is inserted into a text. Then newer string is the collection all characters present in both the string. Example : Input : text : whatthat string : is index : 4 Output : whatisthat C/C++/* C program to insert a string into given string */ //Save it as InsertString.c #include Input: Enter a string : Sanjay Dutt Enter a string to be inserted : Sunil Enter the position at which string to be inserted : 6 Output: The new String is SanjaySunil Dutt Java/* Java program to insert a string into given string */ //Save it as InsertString.java import java.io.*; import java.util.Scanner; public class InsertString { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int i, pos; System.out.println("Enter a string : "); String str = scanner.nextLine(); System.out.println("Enter a string to be inserted : "); String insertStr = scanner.nextLine(); System.out.println("Enter the position at which string to be inserted : "); pos = scanner.nextInt(); int j=0; //Converting string str to character array char strArray[] = str.toCharArray(); /* Declaring the new character array of sum of length of string and string to be inserted*/ char newStrArray[] = new char[str.length()+insertStr.length()]; //Insert elements of string into new string upto index pos from start for(i=0;i Input: Enter a string : Sanjay Dutt Enter a string to be inserted : Sunil Enter the position at which string to be inserted : 6 Output: The new string is : SanjaySunil Dutt Chương trình liên quan1) Chương trình nối một Chuỗi vào một Chuỗi khác2) Chương trình xóa các nguyên âm khỏi Chuỗi 3) Chương trình xóa số đã cho khỏi chuỗi 4) Chương trình thêm các số có trong 5) Program to find maximum number of 1s in a substring of a String 6) Count Number of Words in a String 7) Find Occurrence Of Each Word In a Sentence 8) Print All Unique Words Of A String 9) Program To Print Unique Word Of A String Using Set 10) Program to Compare Two Strings Share Me Show
Làm cách nào để chèn một chuỗi vào một chuỗi khác trong C?Trong C, hàm strcat() dùng để nối hai chuỗi. . Lấy chuỗi đích Tìm ký tự NULL Sao chép chuỗi nguồn bắt đầu bằng ký tự NULL của chuỗi đích Nối một ký tự NULL vào chuỗi đích sau khi được sao chép Làm cách nào để chèn giá trị chuỗi trong C?Bạn có thể khởi tạo chuỗi theo một số cách. Hãy lấy một ví dụ khác. char c[5] = "abcde"; Ở đây, chúng tôi đang cố gán 6 ký tự (ký tự cuối cùng là '\0' ) cho một char . |