Thursday 1 February 2018

String in C Language

Strings characters का समूह होता है | Strings One-dimensional array होता है, जिसमे सिर्फ characters होते है | String का आखिरी character 'NULL'(\0) होता है | अगर पूरा string लिखना हो तो उसे double quotes ( " " ) में लिखा जाता है | अगर एक-एक character को लिखना हो तो उसे single quotes ( ' ' ) में लिखा जाता है | String का data type character (char) होता है 

Example for Single Character String

char str1[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; 

Example for Multiple Character String

char str2[6] = "Hello"; 

String Working with size (sizeof)

Program में हर एक String के initialization में अलग-अलग size है | दिए हुए array के size की memory allocate की जाती है | अगर Array का size नहीं दिया जाता तो जितनी size string की है उतनी size array allocate करता है |


String Library Functions

इन Functions को Program में इस्तेमाल करना हो तो string.h या strings.h इन header file को include करना पड़ता है |


String FunctionDescription
strcatएक String से दूसरे String को जोड़ा जाता है |
strchrदिए हुए string से एक character का पहला occurrence के आगे का string pointer को return करता है |
strcmpदो String को Compare किया जाता है | ये case-sensetive है |
strcmpiदो String को Compare किया जाता है | ये case-sensetive नहीं है |
strcpyएक string को दूसरे string में copy करता है |
strdupString का duplicate बनाता है |
strlenString की Length निकाली जाती है |
strlwrUppercase के Characters को Lowercase में convert किया जाता है |
strncatदिए हुए number के जितने character है उनसे String को जोड़ा जाता है |
strncpyदिए हुए number के जितने character एक string से दूसरे string में copy किया जाता है |
strnsetदिए हुए number और दिए हुए character के हिसाब से string को replace करता है |
strrchrदिए हुए string से एक character का आखिरी occurrence के आगे का string pointer को return करता है |
strrevString को उलटी दिशा से print करता है |
strrstrदिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |
strsetदिए हुए character से पूरे string को replace करता है |
strstrदिए हुए String का पहला string occurrence के आगे का string pointer को return करता है |
struprLowercase के Characters को Uppercase में convert किया जाता है |

strcat() - String Function

strcat ये String का एक Function है | एक String से दूसरे String को जोड़ा जाता है |
 
Syntax for strcat()

strcat(destination_string, source_string);

strchr() - String Function

दिए हुए string से एक character का पहला occurrence के आगे का string pointer को return करता है |

Syntax for strchr()

strchr(string, int character);

string - ये एक normal string है |
int character - ये दिए हुए string में से दिए हुए character का पहला occurrence के आगे का string pointer को return करता है |
अगर दिया हुआ character string को नहीं मिलता तो वो NULL character return करता है |

strcmp() - String Function

दो String को Compare किया जाता है | ये case-sensetive है |

Syntax for strcmp()

strcmp(string1, string2);

string1 -ये वो String है जिसके साथ String2 को Compare किया जाता है |
string2 - ये वो String है जिसके साथ String1 को Compare किया जाता है |
अगर दोनों string एक जैसे होते है तो ये '0' return करता है |अगर दोनों string अलग-अलग होते है तो '1' या '-1' return करता है |

strcmpi() - String Function

दो String को Compare किया जाता है | ये case-sensetive नहीं है |

Syntax for strcmpi()

strcmpi(string1, string2);

string1 - ये वो String है जिसके साथ String2 को Compare किया जाता है |
string2 - ये वो String है जिसके साथ String1 को Compare किया जाता है |
अगर दोनों string एक जैसे होते है तो ये '0' return करता है |अगर दोनों string अलग-अलग होते है तो '1' या '-1' return करता है |

strcpy() - String Function

दो String को Compare किया जाता है | ये case-sensetive नहीं है |

Syntax for strcpy()

strcpy(destination_string, source_string);

destination_string - ये वो parameter है जिसपर source के string की value copy की जाती है | अगर destination string पर कोई value भी हो तो वो overwrite हो जाती है |
source_string - ये वो parameter है जिसकी value destination पर copy की जाती है |

strdup() - String Function

String का duplicate बनाता है |

Syntax for strdup()

strdup(string);

string - ये String है जिसका duplicate बनाया जाता है |


strlen() - String Function

String की Length निकाली जाती है |

Syntax for strlen()

strlen(string);

string - ये एक normal string है, जिसकी length निकली जाती है |
strlen से निकला हुआ output integer value ही होती है ,ये किसी दूसरे integer variable में भी store करके रख सकते है |

strlwr() - String Function

Uppercase के Characters को Lowercase में convert किया जाता है |

Syntax for strlwr()

strlwr(string);

string - ये वो string है जिसको lowercase में convert किया जाता है |

strncat() - String Function

दिए हुए number के जितने character है उनसे String को जोड़ा जाता है |

Syntax for strncat()

strncat(destination_string, source_string, size_t num);

destination_string - ये वो string जिसके साथ source string को जोड़ा जाता है |
source_string - ये वो string जिसके साथ destination string को बाद में जोड़ा जाता है |
size_t num - यहाँ पर जो integer value दी जाती है उतने character वो source string से लेता है |

strncpy() - String Function

दिए हुए number के जितने character एक string से दूसरे string में copy किया जाता है |

Syntax for strncpy()

strncpy(destination_string, source_string, size_t num);

destination_string - ये वो parameter है जिसपर source के string की value copy की जाती है | अगर destination string पर कोई value भी हो तो वो overwrite हो जाती है |
source_string - ये वो parameter है जिसकी value destination पर copy की जाती है |
size_t num - यहाँ पर जो integer value दी जाती है उतने character वो destination string से लेकर source string पर copy कर देता है |

strnset() - String Function

दिए हुए number और दिए हुए character के हिसाब से string को replace करता है |

Syntax for strnset()

strnset(string, char ch, int c);

destination_string - ये एक normal string है |
char ch - ये वो character है जिससे string के हर character को replace किया जाता है |
int c - यहाँ पर जितना number है उतने character string से replace किया जाते है |

strrchr() - String Function

दिए हुए string से एक character का आखिरी occurrence के आगे का string pointer को return करता है |

Syntax for strrchr()

strrchr(string, int character);

string - ये एक normal string है |
int character - ये वो character है जिसका आखिरी occurrence के आगे का string pointer को return किया जाता है |


strrev() - String Function

String को उलटी दिशा से print करता है |

Syntax for strrev()

strrev(string);

string - ये एक normal string है |

strrstr() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strrstr()

strrstr(string1, string2);

string1 - ये एक normal string है |
string2 - string1 में से ये string find करके उसका आखिरी occurrence pointer को return करता है |

strset() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strset()

strset(string, int character);

string - ये एक normal string है |
int character - ये एक-एक character करके सभी characters को replace कर देता है |

strstr() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strstr()

strstr(string1, string2);

string - ये एक normal string है |
int character - string1 में से ये string find करके उसका पहला occurrence pointer को return करता है |

strupr() - String Function

Lowercase के Characters को Uppercase में convert किया जाता है |

Syntax for strupr()

strupr(string);

string - ये वो string है जिसको Uppercase में convert किया जाता है |

Share this

0 Comment to "String in C Language"

Post a Comment