String ??
String adalah sebuah array yang bertipe char yang diakhiri dengan karakter null ().
Sebagai contoh, deklarasi dibawah ini merupakan deklasai sebuah array yang bertipe char, dan bisa disamakan dengan deklarasi sebuah string dengan nama st.
char array_ch[7] = {`H’, `e’, `l’, `l’, `o’, `!’, `’};
Dalam C, karakter null dapat digunakan untuk menandai akhir sebuah string. Setiap karakter akan membutuhkan 1 byte dalam memori.
Sekumpulan karakter-karakter yang diapit dengan kutip ganda (“”) disebut sebagai konstanta string. C akan secara otomatis menambahkan karakter null pada setiap akhir konstanta string untuk menandakan akhir dari sebuah string.

Mendeklarasikan String
Cara pendeklarasian variabel-variabel yang berjenis string dapat dilakukan dengan cara sebagai berikut :
char nama[21];
char *nama2;
Kedua cara tersebut dapat dipergunakan. Cara ke-1 adalah dengan membuat suatu array char sebanyak 21 karakter. Pada langkah ini, variabel nama hanya diperbolehkan diisi sampai panjangnya 20 karakter karena untuk menutup suatu string membutuhkan satu byte untuk karater null.
Cara ke-2 adalah dengan membuat suatu variabel ke suatu pointer char, yang menunjuk ke suatu alamat di memori yang berisi data stringnya (isinya).
Cara pendeklarasian yang ke-1 (array) lebih baik dari pada yang pointer,  karena kalau membuat string sebagai pointer maka ketika akan mengisikan data maka harus meminta tempat dulu ke memori untuk menampung datanya contohnya dengan malloc, karena ketika kita tidak meminta alokasi memori dulu, maka ada kemungkinan data string yang diisikan ke pointer akan mengisi ke suatu tempat yang dimiliki oleh variabel lain.


Inisialisasi String
Cara untuk menginisialisasi string, dapat dilakukan dengan salah satu cara di bawah ini :

char nama[]=”Ini adalah string”;
char nama2[]={‘i’,'n’,'i’, ‘ ‘,’s',’t',’r',’i',’n',’g',”};
char nama3[5]=”BUDI”;
char nama4[5]={‘B’,'u’,'d’,'i’,”}
char *nama5=”Ini juga string”;

Untuk mengisi suatu string caranya adalah :

strcpy(nama,”Ini string”);
nama5=”Ini juga string”;

Coba diperhatikan, untuk string yang dideklarasikan sebagai sebuah array karakter, pengisian nilainya adalah dengan menggunakan suatu perintah strcpy yang berguna untuk mengisikan suatu string ke string lain. Pengisiannya tidak boleh langsung. Tetapi jika string dideklarasikan sebagai sebuah pointer karakter, maka pengisiannya boleh diisikan secara langsung.

Fungsi-Fungsi Manipulasi String
  • gets dan puts
Fungsi gets digunakan untuk membaca data berupa string dari keyboard.
Fungsi puts digunakan untuk menampilkan suatu string ke layar (monitor).
Contoh program :
#include <stdio.h>
int main(void)
{
   char string[80];
   printf(“Masukan Sebuah string:”);gets(string);
   puts(string);
   return 0;
}
Hasil run program :
Masukan Sebuah string:String adalah sekumpulan karakter String adalah sekumpulan karakter



  • strlen
Fungsi strlen digunakan untuk mengetahui panjang suatu string.
Contoh progam :
#include <stdio.h>
#include <string.h>
int main(void)
{
   char string[80];
   int panjang;
   printf(“Masukan String: “);gets(string);
   panjang=strlen(string);
   printf(“Panjang String adalah %i karakter\n”,panjang);
   return 0;
}
Hasil run program :
Masukan String: ABCDEFGHIJKLMNOPQRSTUVWXYZ Panjang String adalah 26 karakter

  • strcpy dan strncpy
Fungsi strcpy berfungsi untuk menyalin isi suatu string ke string lain.
Fungsi strncpy berfungsi untuk menyalin isi suatu string ke string lain sebanyak n karakter.
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char string[31];
   char *str1 = “Ini adalah sebuah string”;
   char str2[31];
   strcpy(string, str1);
   printf(“Isi String : %s\n”, string);
   strncpy(str2,str1,10);
   str2[10]=”;// menutup string
   printf(“Isi Str2 : %s”,str2);
   getch();
   return 0;
}
Hasil run program :
Isi String : Ini adalah sebuah string Isi Str2 : Ini adalah



  • strcmp, strncmp, strcmpi dan strncmpi
Fungsi strcmp digunakan untuk membandingkan 2 buah string secara case sensitive.
Fungsi strncmp digunakan untuk membandingkan 2 buah string sebanyak n buah karakter secara case sensitive
Fungsi strcmpi digunakan untuk membandingkan 2 buah string secara case insensitive.
Fungsi strncmpi digunakan untuk membandingkan 2 buah string sebanyak n buah karakter secara case insensitive.
Semua fungsi tersebut akan menghasilkan sebuah nilai integer yang mempunyai ketentuan :
§  Nilai return akan lebih dari 0 (>0) ketika string1 lebih besar dari string2
§  Nilai return akan sama dengan 0 (==0)  ketika string1 sama dengan string 2
§  Nilai return akan kurang dari 0 (<0) ketika string1 lebih kecil dari string 2
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
 char str1[5]=”ABCD”,str2[5]=”abcd”,str3[5]=”BCDE”,str4[5]=”BCda”;
   int hasil;
   hasil=strcmp(str1,str2);
   printf(“Hasil STRCMP : \n”);
   if(hasil==0) printf(“String1 sama dengan String2\n”); else
   if(hasil>0) printf(“String1 lebih besar dari String2\n”); else
   if(hasil<0) printf(“String1 lebih kecil dari String2\n”);
   hasil=strcmpi(str1,str2);
   printf(“Hasil STRCMPI : \n”);
   if(hasil==0) printf(“String1 sama dengan String2\n”); else
   if(hasil>0) printf(“String1 lebih besar dari String2\n”); else
   if(hasil<0) printf(“String1 lebih kecil dari String2\n”);
   hasil=strncmp(str3,str4,3);
   printf(“Hasil STRNCMP : \n”);
   if(hasil==0) printf(“String3 sama dengan String4\n”); else
   if(hasil>0) printf(“String3 lebih besar dari String4\n”); else
   if(hasil<0) printf(“String3 lebih kecil dari String4\n”);
   hasil=strncmpi(str3,str4,3);
   printf(“Hasil STRNCMPI : \n”);
   if(hasil==0) printf(“String3 sama dengan String4\n”); else
   if(hasil>0) printf(“String3 lebih besar dari String4\n”); else
   if(hasil<0) printf(“String3 lebih kecil dari String4\n”);
   getch();
   return 0;
}
Hasil run program :
Hasil STRCMP : String1 lebih kecil dari String2
Hasil STRCMPI :
String1 sama dengan String2
Hasil STRNCMP :
String3 lebih kecil dari String4
Hasil STRNCMPI :
String3 sama dengan String4

  • strcat dan strncat
Fungsi strcat berfungsi untuk menggabungkan 2 buah string.
Fungsi strncat berfungsu untuk menggabungkan 2 buah string sebanyak n karakter.
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char str1[80];
   char str2[15]=”Saya Belajar “;
   char str3[10]=”Turbo C”;
   clrscr();
   strcpy(str1,str2);
   strcat(str1,str3);
   printf(“Hasil penggabungan dengan STRCAT  : %s\n”,str1);
   strcpy(str1,str2);
   strncat(str1,str3,5);
   printf(“Hasil penggabungan dengan STRNCAT : %s\n”,str1);
   getch();
   return 0;
}
Hasil Run program :
Hasil penggabungan dengan STRCAT  : Saya Belajar Turbo C Hasil penggabungan dengan STRNCAT : Saya Belajar Turbo



  • strlwr dan strupr
Fungsi strlwr berguna untuk mengubah isi string menjadi huruf kecil.
Fungsi strupr berguna untuk mengubah isi string menjadi capital.
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char str1[80]=”Saya Belajar Turbo C”;
   clrscr();
   printf(“Normal    : %s\n”,str1);
   strupr(str1);
   printf(“UpperCase : %s\n”,str1);
   strlwr(str1);
   printf(“LowerCase : %s\n”,str1);
   getch();
   return 0;
}
Hasil run program :
Normal    : Saya Belajar Turbo C UpperCase : SAYA BELAJAR TURBO C
LowerCase : saya belajar turbo c

  • strrev
Fungsi strrev berguna untuk membalikan urutan string (reverse).
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char str1[80]=”Saya Belajar Turbo C”;
   clrscr();
   printf(“Normal  : %s\n”,str1);
   strrev(str1);
   printf(“Reverse : %s\n”,str1);
   getch();
   return 0;
}
Hasil run program :
Normal  : Saya Belajar Turbo C Reverse : C obruT rajaleB ayaS



  • strset dan strnset
Fungsi strset berguna untuk mengganti isi suatu string dengan suatu karakter tertentu.
Fungsi strnset berguna untuk mengganti isi suatu string dengan suatu karakter tertentu sebanyak n buah data.
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char str1[21]=”Saya Belajar Turbo C”;
   clrscr();
   strnset(str1,’A',12);
   printf(“Setelah strnset 12 : %s\n”,str1);
   strset(str1,’x');
   printf(“Setelah strset     : %s\n”,str1);
   getch();
   return 0;
}
Hasil run program :
Setelah strnset 12 : AAAAAAAAAAAA Turbo C Setelah strset     : xxxxxxxxxxxxxxxxxxxx

  • strstr
Fungsi strstr berguna untuk mencari urutan pertama suatu string di string lain.
Contoh program :
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
   char str1[21]=”Saya Belajar Turbo C”;
   char str2[6]=”Turbo”;
   char *str3;
   clrscr();
   str3 = strstr(str1, str2);
   printf(“String Asli: %s\n”,str1);
   printf(“Sub string : %s\n”, str3);
   printf(“Posisi     : %d\n”,str3-str1);
   getch();
   return 0;
}
Hasil run program :
String Asli: Saya Belajar Turbo C Sub string : Turbo C
Posisi     : 13

Macam Fungsi Dari String.h c dan c++

Unknown 2 6:41 AM

String ?? String adalah sebuah array yang bertipe char yang diakhiri dengan karakter null (). Sebagai contoh, deklarasi dibawah ini meru...


a perfect maze, there is one and only one path from any point in the maze to any other point. That is, there are no inaccessible sections, no circular paths, and no open regions. A perfect maze can be generated easily with a computer using a depth first search algorithm.

A two dimensional maze can be represented as a rectangular array of square cells. Each cell has four walls. The state of each wall (north, south, east, and west) of each cell is maintained in a data structure consisting of an array of records. Each record stores a bit value that represents the state of each wall in a cell. To create a path between adjacent cells, the exit wall from the current cell and the entry wall to the next cell are removed. For example, if the next cell is to the right (east) of the current cell, remove the right (east) wall of the current cell and the left (west) wall of the next cell.
01create a CellStack (LIFO) to hold a list of cell locations
02set TotalCells = number of cells in grid
03choose a cell at random and call it CurrentCell
04set VisitedCells = 1
05 
06while VisitedCells < TotalCells
07 
08      find all neighbors of CurrentCell with all walls intact
09      if one or more found
10            choose one at random
11            knock down the wall between it and CurrentCell
12            push CurrentCell location on the CellStack
13            make the new cell CurrentCell
14            add 1 to VisitedCells else
15            pop the most recent cell entry off the CellStack
16            make it CurrentCell endIf
17 
18endWhile
Here it this..the source code :
001#include<stdio.h>
002#include<conio.h>
003#include<stdlib.h>
004#include<time.h>
005 
006#define MAX 61  // 30 * 2 + 1
007#define CELL 900  // 30 * 30
008#define WALL 1
009#define PATH 0
010 
011void init_maze(int maze[MAX][MAX]);
012void maze_generator(int indeks, int maze[MAX][MAX], int backtrack_x[CELL], int bactrack_y[CELL], int x, int y, int n, int visited);
013void print_maze(int maze[MAX][MAX], int maze_size);
014int is_closed(int maze[MAX][MAX], int x, int y);
015 
016int main(void)
017{
018    srand((unsigned)time(NULL));
019 
020    int size;
021    int indeks = 0;
022    printf("MAZE CREATOR\n\n");
023    printf("input  (0 ~ 30): ");
024    scanf("%d", &size);
025    printf("\n");
026    int maze[MAX][MAX];
027    int backtrack_x[CELL];
028    int backtrack_y[CELL];
029 
030    init_maze(maze);
031 
032    backtrack_x[indeks] = 1;
033    backtrack_y[indeks] = 1;
034 
035    maze_generator(indeks, maze, backtrack_x, backtrack_y, 1, 1, size, 1);
036    print_maze(maze, size);
037 
038    getch();
039    return 0;
040}
041 
042void init_maze(int maze[MAX][MAX])
043{
044     for(int a = 0; a < MAX; a++)
045     {
046         for(int b = 0; b < MAX; b++)
047         {
048             if(a % 2 == 0 || b % 2 == 0)
049                 maze[a][b] = 1;
050             else
051                 maze[a][b] = PATH;
052         }
053     }
054}
055 
056void maze_generator(int indeks, int maze[MAX][MAX], int backtrack_x[CELL], int backtrack_y[CELL], int x, int y, int n, int visited)
057{
058    if(visited < n * n)
059    {
060        int neighbour_valid = -1;
061        int neighbour_x[4];
062        int neighbour_y[4];
063        int step[4];
064 
065        int x_next;
066        int y_next;
067 
068        if(x - 2 > 0 && is_closed(maze, x - 2, y))  // upside
069        {
070            neighbour_valid++;
071            neighbour_x[neighbour_valid]=x - 2;;
072            neighbour_y[neighbour_valid]=y;
073            step[neighbour_valid]=1;
074        }
075 
076        if(y - 2 > 0 && is_closed(maze, x, y - 2))  // leftside
077        {
078            neighbour_valid++;
079            neighbour_x[neighbour_valid]=x;
080            neighbour_y[neighbour_valid]=y - 2;
081            step[neighbour_valid]=2;
082        }
083 
084        if(y + 2 < n * 2 + 1 && is_closed(maze, x, y + 2))  // rightside
085        {
086            neighbour_valid++;
087            neighbour_x[neighbour_valid]=x;
088            neighbour_y[neighbour_valid]=y + 2;
089            step[neighbour_valid]=3;
090 
091        }
092 
093        if(x + 2 < n * 2 + 1 && is_closed(maze, x + 2, y))  // downside
094        {
095            neighbour_valid++;
096            neighbour_x[neighbour_valid]=x+2;
097            neighbour_y[neighbour_valid]=y;
098            step[neighbour_valid]=4;
099        }
100 
101        if(neighbour_valid == -1)
102        {
103            // backtrack
104            x_next = backtrack_x[indeks];
105            y_next = backtrack_y[indeks];
106            indeks--;
107        }
108 
109        if(neighbour_valid!=-1)
110        {
111            int randomization = neighbour_valid + 1;
112            int random = rand()%randomization;
113            x_next = neighbour_x[random];
114            y_next = neighbour_y[random];
115            indeks++;
116            backtrack_x[indeks] = x_next;
117            backtrack_y[indeks] = y_next;
118 
119            int rstep = step[random];
120 
121            if(rstep == 1)
122                maze[x_next+1][y_next] = PATH;
123            else if(rstep == 2)
124                maze[x_next][y_next + 1] = PATH;
125            else if(rstep == 3)
126                maze[x_next][y_next - 1] = PATH;
127            else if(rstep == 4)
128                maze[x_next - 1][y_next] = PATH;
129            visited++;
130        }
131 
132        maze_generator(indeks, maze, backtrack_x, backtrack_y, x_next, y_next, n, visited);
133    }
134}
135 
136void print_maze(int maze[MAX][MAX], int maze_size)
137{
138     for(int a = 0; a < maze_size * 2 + 1; a++)
139     {
140         for(int b = 0; b < maze_size * 2 + 1; b++)
141         {
142             if(maze[a][b] == WALL)
143                 printf("#");
144             else
145                 printf(" ");
146         }
147         printf("\n");
148     }
149}
150 
151int is_closed(int maze[MAX][MAX], int x, int y)
152{
153    if(maze[x - 1][y]  == WALL
154       && maze[x][y - 1] == WALL
155       && maze[x][y + 1] == WALL
156       && maze[x + 1][y] == WALL
157    )
158        return 1;
159 
160    return 0;
161}

Perfect Maze Generator

Unknown Reply 10:06 AM

a perfect maze, there is one and only one path from any point in the maze to any other point. That is, there are no inaccessible section...

Berikut Source Codenya :

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,d,x;

printf("a : ");
scanf("%d",&a);

printf("b : ");
scanf("%d",&b);

printf("c : ");
scanf("%d",&c);

printf("d : ");
scanf("%d",&d);

if(b<a)
{
x=b;
b=a;
a=x;
}
if(c<a)
{
x=c;
c=a;
a=x;
}
if(d<a)
{
x=d;
d=a;
a=x;
}
if(c<b)
{
x=b;
b=c;
c=x;
}
if(d<a)
{
x=a;
a=d;
d=x;
}
if(d<b)
{
x=b;
b=d;
d=x;
}
if(d<c)
{
x=c;
c=d;
d=x;
}

printf("setelah diurutkan %d %d %d %d",a,b,c,d);

getch();
return 0;
}

Mengurutkan 4 Bilangan Ascending dengan IF C++

Unknown Reply 8:07 PM

Berikut Source Codenya : #include<stdio.h> #include<conio.h> int main() { int a,b,c,d,x; printf("a : "); scanf...

The String class of the .NET framework provides many built-in methods to facilitate the comparison and manipulation of strings. It is now a trivial matter to get data about a string, or to create new strings by manipulating current strings. The Visual Basic .NET language also has inherent methods that duplicate many of these functionalities.

Types of String Manipulation Methods

In this section you will read about several different ways to analyze and manipulate your strings. Some of the methods are a part of the Visual Basic language, and others are inherent in the String class.
Visual Basic .NET methods are used as inherent functions of the language. They may be used without qualification in your code. The following example shows typical use of a Visual Basic .NET string-manipulation command:
Dim aString As String = "SomeString"
Dim bString As String
bString = Mid(aString, 3, 3)
In this example, the Mid function performs a direct operation on aString and assigns the value to bString.
You can also manipulate strings with the methods of the String class. There are two types of methods in String: shared methods and instance methods.
A shared method is a method that stems from the String class itself and does not require an instance of that class to work. These methods can be qualified with the name of the class (String) rather than with an instance of the String class. For example:
Dim aString As String
bString = String.Copy("A literal string")
In the preceding example, the String.Copy method is a static method, which acts upon an expression it is given and assigns the resulting value to bString.
Instance methods, by contrast, stem from a particular instance of String and must be qualified with the instance name. For example:
Dim aString As String = "A String"
Dim bString As String
bString = aString.SubString(2,6) ' bString = "String"
In this example, the SubString method is a method of the instance of String (that is, aString). It performs an operation on aString and assigns that value to bString.

Nothing and Strings

The Visual Basic runtime and the .NET Framework evaluate Nothing differently when it comes to strings. Consider the following example:
Dim MyString As String = "This is my string"
Dim stringLength As Integer
' Explicitly set the string to Nothing.
MyString = Nothing
' stringLength = 0
stringLength = Len(MyString)
' This line, however, causes an exception to be thrown.
stringLength = MyString.Length
The Visual Basic .NET runtime evaluates Nothing as an empty string; that is, "". The .NET Framework, however, does not, and will throw an exception whenever an attempt is made to perform a string operation on Nothing.

Comparing Strings

You can compare two strings by using the String.Compare method. This is a static, overloaded method of the base string class. In its most common form, this method can be used to directly compare two strings based on their alphabetical sort order. This is similar to the Visual Basic StrComp Function function. The following example illustrates how this method is used:
Dim myString As String = "Alphabetical"
Dim secondString As String = "Order"
Dim result As Integer
result = String.Compare (myString, secondString)
This method returns an integer that indicates the relationship between the two compared strings based on the sorting order. A positive value for the result indicates that the first string is greater than the second string. A negative result indicates the first string is smaller, and zero indicates equality between the strings. Any string, including an empty string, evaluates to greater than a null reference.
Additional overloads of the String.Compare method allow you to indicate whether or not to take case or culture formatting into account, and to compare substrings within the supplied strings. For more information on how to compare strings, see String.Compare Method. Related methods include String.CompareOrdinal Method and String.CompareTo Method.

Searching for Strings Within Your Strings

There are times when it is useful to have data about the characters in your string and the positions of those characters within your string. A string can be thought of as an array of characters (Char instances); you can retrieve a particular character by referencing the index of that character through the Chars property. For example:
Dim myString As String = "ABCDE"
Dim myChar As Char
myChar = myString.Chars(3) ' myChar = "D"
You can use the String.IndexOf method to return the index where a particular character is encountered, as in the following example:
Dim myString As String = "ABCDE"
Dim myInteger As Integer
myInteger = myString.IndexOf("D")  ' myInteger = 3
In the previous example, the IndexOf method of myString was used to return the index corresponding to the first instance of the character "C" in the string. IndexOf is an overloaded method, and the other overloads provide methods to search for any of a set of characters, or to search for a string within your string, among others. The Visual Basic .NET command InStr also allows you to perform similar functions. For more information of these methods, see String.IndexOf Method and InStr Function. You can also use the String.LastIndexOf Method to search for the last occurrence of a character in your string.

Creating New Strings from Old

When using strings, you may want to modify your strings and create new ones. You may want to do something as simple as convert the entire string to uppercase, or trim off trailing spaces; or you may want to do something more complex, such as extracting a substring from your string. The System.String class provides a wide range of options for modifying, manipulating, and making new strings out of your old ones.
To combine multiple strings, you can use the concatenation operators (& or +). You can also use the String.Concat Method to concatenate a series of strings or strings contained in objects. An example of the String.Concat method follows:
Dim aString As String = "A"
Dim bString As String = "B"
Dim cString As String = "C"
Dim dString As String = "D"
Dim myString As String
' myString = "ABCD"
myString = String.Concat(aString, bString, cString, dString) 
You can convert your strings to all uppercase or all lowercase strings using either the Visual Basic .NET functions UCase Function and LCase Function or the String.ToUpper Method and String.ToLower Method methods. An example is shown below:
Dim myString As String = "UpPeR oR LoWeR cAsE"
Dim newString As String
' newString = "UPPER OR LOWER CASE"
newString = UCase(myString)
' newString = "upper or lower case"
newString = LCase(myString)
' newString = "UPPER OR LOWER CASE"
newString = myString.ToUpper
' newString = "upper or lower case"
newString = myString.ToLower
The String.Format method and the Visual Basic .NET Format command can generate a new string by applying formatting to a given string. For information on these commands, see Format Function or String.Format Method.
You may at times need to remove trailing or leading spaces from your string. For instance, you might be parsing a string that had spaces inserted for the purposes of alignment. You can remove these spaces using the String.Trim Method function, or the Visual Basic .NET Trim function. An example is shown:
Dim spaceString As String = _
"        This string will have the spaces removed        "
Dim oneString As String
Dim twoString As String
' This removes all trailing and leading spaces.
oneString = spaceString.Trim
' This also removes all trailing and leading spaces.
twoString = Trim(spaceString)
If you only want to remove trailing spaces, you can use the String.TrimEnd Method or the RTrim function, and for leading spaces you can use the String.TrimStart Method or the LTrim function. For more details, see LTrim, RTrim, and Trim Functions functions.
The String.Trim functions and related functions also allow you to remove instances of a specific character from the ends of your string. The following example trims all leading and trailing instances of the "#" character:
Dim myString As String = "#####Remove those!######"
Dim oneString As String
OneString = myString.Trim("#")
You can also add leading or trailing characters by using the String.PadLeft Method or the String.PadRight Method.
If you have excess characters within the body of your string, you can excise them by using the String.Remove Method, or you can replace them with another character using the String.Replace Method. For example:
Dim aString As String = "This is My Str@o@o@ing"
Dim myString As String
Dim anotherString As String
' myString = "This is My String"
myString = aString.Remove(14, 5)
' anotherString = "This is Another String"
anotherString = myString.Replace("My", "Another")
You can use the String.Replace method to replace either individual characters or strings of characters. The Visual Basic .NET Mid Statement can also be used to replace an interior string with another string.
You can also use the String.Insert Method to insert a string within another string, as in the following example:
Dim aString As String = "This is My Stng"
Dim myString As String
' Results in a value of "This is My String".
myString = aString.Insert(13, "ri")
The first parameter that the String.Insert method takes is the index of the character the string is to be inserted after, and the second parameter is the string to be inserted.
You can concatenate an array of strings together with a separator string by using the String.Join Method. Here is an example:
Dim shoppingItem(2) As String
Dim shoppingList As String
shoppingItem(0) = "Milk"
shoppingItem(1) = "Eggs"
shoppingItem(2) = "Bread"
shoppingList = String.Join(",", shoppingItem)
The value of shoppingList after running this code is "Milk,Eggs,Bread". Note that if your array has empty members, the method still adds a separator string between all the empty instances in your array.
You can also create an array of strings from a single string by using the String.Split Method. The following example demonstrates the reverse of the previous example: it takes a shopping list and turns it into an array of shopping items. The separator in this case is an instance of the Char data type; thus it is appended with the literal type character c.
Dim shoppingList As String = "Milk,Eggs,Bread"
Dim shoppingItem(2) As String
shoppingItem = shoppingList.Split(","c)
The Visual Basic .NET Mid Function can be used to generate substrings of your string. The following example shows this functions in use:
Dim aString As String = "Left Center Right"
Dim rString, lString, mString As String
' rString = "Right"
rString = Mid(aString, 13)
' lString = "Left"
lString = Mid(aString, 1, 4)
' mString = "Center"
mString = Mid(aString, 6,6)
Substrings of your string can also be generated using the String.Substring Method. This method takes two arguments: the character index where the substring is to start, and the length of the substring. The String.Substring method operates much like the Mid function. An example is shown below:
Dim aString As String = "Left Center Right"
Dim subString As String
' subString = "Center"
subString = aString.SubString(5,6)
There is one very important difference between the String.SubString method and the Mid function. The Mid function takes an argument that indicates the character position for the substring to start, starting with position 1. The String.SubString method takes an index of the character in the string at which the substring is to start, starting with position 0. Thus, if you have a string "ABCDE", the individual characters are numbered 1,2,3,4,5 for use with the Mid function, but 0,1,2,3,4 for use with the System.String function.

String Manipulation Vb.Net

Unknown Reply 8:04 PM

The String class of the .NET framework provides many built-in methods to facilitate the comparison and manipulation of strings. It is now...

Strcat, Fungsi untuk Menggabungkan String

Berikut ini contoh fungsi penggabungan string sederhana ,dia pake strcat,jagan lupa pake header string juga,



  
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main(void)
  5. {
  6.   char string1[50]="Aku mencintaimu ";
  7.   char string2[50]="dengan tulus";
  8.  
  9.   strcat(string1,string2); /*artinya gabung string2 ke string1*/
  10.  printf("%s",string1); /*print string yang udah digabung*/
  11.   return 0;
  12. }

    //Hasilnya : Aku mencintaimu dengan tulus

Cara Menggabungkan String di C

Unknown Reply 5:55 AM

Strcat, Fungsi untuk Menggabungkan String Berikut ini contoh fungsi penggabungan string sederhana ,dia pake strcat,jagan lupa pake header ...

Search

Ikuti Channel Youtube Aku Yaa.. Jangan Lupa di subscribe. Terima kasih.

Popular Posts

Translate