Operation string, python string operation

Source: Internet
Author: User

Operation string, python string operation

Public class OperationString {public static void main (String [] args) {String str [] = new String [4]; // define a 4-character string array str [0] = "first"; str [1] = "second"; StringBuffer sb1 = new StringBuffer (str [0]); // use the string str [0] to construct a StringBuffer. The content of sb1 is "first"; sb1.insert (0, str [1]); // before the position of the StringBuffer object is 0, insert the String str [1], StringBuffer, and the content of sb1 is "secondfirst"; str [2] = new String (sb1 ); // The StringBuffer object sb1 is used to construct and generate the str [2] string, which assigns the value of sb1 to str [2], in this case, the str [2] content is "secondfirst" StringBuffer sb2 = new StringBuffer (); // A StringBuffer object sb2 is constructed by default, the initial content is empty, and the content of sb2 is: "" sb2.append ('D'); // append the character 'D' to the end of the StringBuffer object sb2. The content of sb2 is: "D" sb2.append ("admin "); // append the string "admin" to the end of the StringBuffer object sb2. The content of sb2 is "D admin" sb2.insert (1, "ear "); // Insert the string "ear ", the content of sb2 is "Dear admin" str [3] = new String (sb2); // The StringBuffer object sb2 constructs the str [3], assign the value of sb2 to str [3], str [3] = "Dear admin" for (int I = 0; I <4; I ++) {System. out. println ("str [" + I + "] =" + str [I]) ;}}

Running result:


String operations

This should be well written.

The order may be slightly different:
# Include <stdio. h>
# Include <malloc. h>
# Include <string. h>

Void main ()
{
Char line [100];
Char * str1 = NULL, * str2 = NULL, * str3 = NULL, * p = NULL, * str4 = NULL;
Int n, m;

Printf ("String1 :");
Memset (lines, 0,100 );
Gets (line );

Str1 = (char *) malloc (strlen (line) + 1 );
Strcpy (str1, line );

Printf ("String1 :");
Memset (lines, 0,100 );
Gets (line );

Str2 = (char *) malloc (strlen (line) + 1 );
Strcpy (str2, line );

Printf ("n :");
Scanf ("% d", & n );
If (n-1 <strlen (str1 ))
{
Str1 = (char *) realloc (str1, strlen (str1) + strlen (str2) + 1 );
Strncat (str1, str2, n );
Printf ("after cat, % s \ n", str1 );
}
Else
{
Printf ("out of bound \ n ");
}

Fflush (stdin );
Printf ("String3 :");
Memset (lines, 0,100 );
Gets (line );

Str3 = (char *) malloc (strlen (line) + 1 );
Strcpy (str3, line );

P = strstr (str1, str3 );
If (p)
{
Printf ("Position: % d \ n", p-str1 );
}
Else
{
Printf ("m :");
Scanf ("% d", & m );

Str4 = (char *) malloc (strlen (str1) + strlen (str2) + 1 );
Memset (str4, 0, strlen (str1) + strlen (str2) + 1 );
If (m-1 <strlen (str1 ))
{
Strncpy (str4, str1 m-1 );
Strcat (str4, str3 );
Strcat (str4, str1 + m-1 );
Printf ("New string: % s \ n", str4 );
}
Else
{
Printf ("out of bound \ n ");
}
}
}... Remaining full text>

C # string operations

If you want to write so many words, check the reference document directly. I can only answer you. This is too simple, because you are too lazy, so I am too lazy to write code for you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.