codeparrot/xlcost-text-to-code huggingface dataset:
Number of sub | C # program to find the number of sub - Strings of s1 which are anagram of any sub - String of s2 ; This function returns true if contents of arr1 [ ] and arr2 [ ] are same , otherwise false . ; This function search for all permutations of String pat [ ] in String txt [ ] ; countP [ ] : Store count of all characters of pattern countTW [ ] : Store count of current window of text ; Traverse through remaining characters of pattern ; Compare counts of current window of text with counts of pattern [ ] ; cout << pat << " ▁ " << txt << " ▁ " ; ; Add current character to current window ; Remove the first character of previous window ; Check for the last window in text ; Function to return the number of sub - Strings of s1 that are anagrams of any sub - String of s2 ; initializing variables ; outer loop for picking starting point ; loop for different length of subStrings ; If s2 has any subString which is anagram of s1 . substr ( i , len ) ; increment the count ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int MAX_LEN = 1005 ; static int MAX_CHAR = 26 ; static int ALL_CHARS = 256 ; static bool compare ( char [ ] arr1 , char [ ] arr2 ) { for ( int i = 0 ; i < ALL_CHARS ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } static bool search ( String pat , String txt ) { int M = pat . Length ; int N = txt . Length ; int i ; char [ ] countP = new char [ ALL_CHARS ] ; char [ ] countTW = new char [ ALL_CHARS ] ; for ( i = 0 ; i < M ; i ++ ) { ( countP [ pat [ i ] ] ) ++ ; ( countTW [ txt [ i ] ] ) ++ ; } for ( i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) { return true ; } ( countTW [ txt [ i ] ] ) ++ ; countTW [ txt [ i - M ] ] -- ; } if ( compare ( countP , countTW ) ) return true ; return false ; } static int calculatesubString ( String s1 , String s2 , int n ) { int count = 0 , j = 0 , x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int len = 1 ; len <= n - i ; len ++ ) { if ( search ( s1 . Substring ( i , len ) , s2 ) ) { count = count + 1 ; } } } return count ; } public static void Main ( String [ ] args ) { String str1 = " PLEASEHELPIMTRAPPED " ; String str2 = " INAKICKSTARTFACTORY " ; int len = str1 . Length ; Console . WriteLine ( calculatesubString ( str1 , str2 , len ) ) ; } }
Sum of the alphabetical values of the characters of a string | C # implementation of the approach ; Function to find string score ; Driver code
using System ; class GFG { static int strScore ( String [ ] str , String s , int n ) { int score = 0 , index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == s ) { for ( int j = 0 ; j < s . Length ; j ++ ) score += s [ j ] - ' a ' + 1 ; index = i + 1 ; break ; } } score = score * index ; return score ; } public static void Main ( String [ ] args ) { String [ ] str = { " sahil " , " shashanak " , " sanjit " , " abhinav " , " mohit " } ; String s = " abhinav " ; int n = str . Length ; int score = strScore ( str , s , n ) ; Console . Write ( score ) ; } }
Minimum swaps to group similar characters side by side ? | checks whether a String has similar characters side by side ; If similar chars side by side , continue ; If we have found a char equal to current char and does not exist side to it , return false ; counts min swap operations to convert a String that has similar characters side by side ; Base case ; considering swapping of i and l chars ; Backtrack ; not considering swapping of i and l chars ; taking Math . min of above two ; Utility swap ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool sameJavaharAdj ( char [ ] str ) { int n = str . Length , i ; HashSet < char > st = new HashSet < char > ( ) ; st . Add ( str [ 0 ] ) ; for ( i = 1 ; i < n ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) { continue ; } if ( st . Contains ( str [ i ] ) & ! st . Equals ( str [ i ] ) ) { return false ; } st . Add ( str [ i ] ) ; } return true ; } static int minSwaps ( char [ ] str , int l , int r , int cnt , int minm ) { if ( l == r ) { if ( sameJavaharAdj ( str ) ) { return cnt ; } else { return int . MaxValue ; } } for ( int i = l + 1 ; i <= r ; i ++ ) { swap ( str , i , l ) ; cnt ++ ; int x = minSwaps ( str , l + 1 , r , cnt , minm ) ; swap ( str , i , l ) ; cnt -- ; int y = minSwaps ( str , l + 1 , r , cnt , minm ) ; minm = Math . Min ( minm , Math . Min ( x , y ) ) ; } return minm ; } static void swap ( char [ ] arr , int i , int j ) { char temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } public static void Main ( ) { String str = " abbaacb " ; int n = str . Length , cnt = 0 , minm = int . MaxValue ; Console . WriteLine ( minSwaps ( str . ToCharArray ( ) , 0 , n - 1 , cnt , minm ) ) ; ; } }
Union | Naive implementation of find ; Naive implementation of union ( )
static int find ( int [ ] parent , int i ) { if ( parent [ i ] == - 1 ) return i ; return find ( parent , parent [ i ] ) ; } static void Union ( int [ ] parent , int x , int y ) { int xset = find ( parent , x ) ; int yset = find ( parent , y ) ; parent [ xset ] = yset ; }
Get K | C # implementation of the above approach ; Function to return the K - th letter from new String . ; finding size = length of new string S ' ; get the K - th letter ; Driver code
using System ; class GFG { static String K_thletter ( String S , int K ) { int N = S . Length ; long size = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( char . IsDigit ( S [ i ] ) ) { size = size * ( S [ i ] - '0' ) ; } else { size += 1 ; } } for ( int i = N - 1 ; i >= 0 ; -- i ) { K %= ( int ) size ; if ( K == 0 && char . IsLetter ( S [ i ] ) ) { return ( String ) " " + S [ i ] ; } if ( char . IsDigit ( S [ i ] ) ) { size = size / ( S [ i ] - '0' ) ; } else { size -= 1 ; } } return null ; } public static void Main ( String [ ] args ) { String S = " geeks2for2" ; int K = 15 ; Console . WriteLine ( K_thletter ( S , K ) ) ; } }
Minimum number of Parentheses to be added to make it valid | C # Program to find minimum number of ' ( ' or ' ) ' must be added to make Parentheses string valid . ; Function to return required minimum number ; maintain balance of string ; It is guaranteed bal >= - 1 ; Driver code ; Function to print required answer
using System ; class GFG { static int minParentheses ( string p ) { int bal = 0 ; int ans = 0 ; for ( int i = 0 ; i < p . Length ; ++ i ) { bal += p [ i ] == ' ( ' ? 1 : - 1 ; if ( bal == - 1 ) { ans += 1 ; bal += 1 ; } } return bal + ans ; } public static void Main ( ) { string p = " ( ) ) " ; Console . WriteLine ( minParentheses ( p ) ) ; } }
Check if suffix and prefix of a string are palindromes | C # implementation of the approach ; Utility reverse ; Swap values of l and r ; Function to check whether the string is a palindrome ; reverse the string to compare with the original string ; check if both are same ; Function to check whether the string has prefix and suffix substrings of length greater than 1 which are palindromes . ; check all prefix substrings ; check if the prefix substring is a palindrome ; If we did not find any palindrome prefix of length greater than 1. ; check all suffix substrings , as the string is reversed now ; check if the suffix substring is a palindrome ; If we did not find a suffix ; Driver code
using System ; class GFG { static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = 0 ; r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } static Boolean isPalindrome ( String r ) { String p = r ; p = reverse ( p ) ; return ( r . Equals ( p ) ) ; } static Boolean CheckStr ( String s ) { int l = s . Length ; int i ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . Substring ( 0 , i ) ) ) { break ; } } if ( i == ( l + 1 ) ) { return false ; } i = 2 ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . Substring ( l - i , i ) ) ) { return true ; } } return false ; } public static void Main ( String [ ] args ) { String s = " abccbarfgdbd " ; if ( CheckStr ( s ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Rotations of a Binary String with Odd Value | C # program to find count of rotations with odd value . ; function to calculate total odd decimal equivalent ; Driver code
using System ; class GFG { static int oddEquivalent ( String s , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '1' ) count ++ ; } return count ; } public static void Main ( ) { String s = "1011011" ; int n = s . Length ; Console . WriteLine ( oddEquivalent ( s , n ) ) ; } }
Minimum operation require to make first and last character same | C # program to find minimum operation require to make first and last character same ; Return the minimum operation requires to make string first and last character same . ; Store indexes of first occurrences of characters . ; Initialize all the elements to - 1 ; Initialize result ; Traverse through all characters ; Find first occurrence ; Update result for subsequent occurrences ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int MAX = 256 ; static int minimumOperation ( String s ) { int n = s . Length ; List < int > first_occ = new List < int > ( ) ; for ( int i = 0 ; i < MAX ; i ++ ) first_occ . Insert ( i , - 1 ) ; int res = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { int x = ( int ) s [ i ] ; if ( first_occ [ x ] == - 1 ) first_occ . Insert ( x , i ) ; else { int last_occ = ( n - i - 1 ) ; res = Math . Min ( res , first_occ [ x ] + last_occ ) ; } } return res ; } public static void Main ( String [ ] args ) { String s = " bacdefghipalop " ; Console . WriteLine ( minimumOperation ( s ) ) ; } }
Lexicographically smallest and largest substring of size k | C # program to find lexicographically largest and smallest substrings of size k . ; Utility compare ; Initialize min and max as first substring of size k ; Consider all remaining substrings . We consider every substring ending with index i . ; Print result . ; Driver Code
using System ; class GFG { static int CompareTo ( String s1 , String s2 ) { for ( int i = 0 ; i < s1 . Length < s2 . Length ; i ++ ) { if ( s1 [ i ] < s2 [ i ] ) return - 1 ; else if ( s1 [ i ] > s2 [ i ] ) return 1 ; } return 0 ; } static void getSmallestAndLargest ( String s , int k ) { String currStr = s . Substring ( 0 , k ) ; String lexMin = currStr ; String lexMax = currStr ; for ( int i = k ; i < s . Length ; i ++ ) { currStr = currStr . Substring ( 1 , k - 1 ) + " " + s [ i ] ; if ( CompareTo ( lexMax , currStr ) < 0 ) lexMax = currStr ; if ( CompareTo ( lexMin , currStr ) > 0 ) lexMin = currStr ; } Console . WriteLine ( lexMin ) ; Console . WriteLine ( lexMax ) ; } public static void Main ( String [ ] args ) { String str = " GeeksForGeeks " ; int k = 3 ; getSmallestAndLargest ( str , k ) ; } }
Program to print the initials of a name with the surname | C # program to print the initials of a name with the surname ; to remove any leading or trailing spaces ; to store extracted words ; forming the word ; when space is encountered it means the name is completed and thereby extracted ; printing the first letter of the name in capital letters ; for the surname , we have to print the entire surname and not just the initial string " t " has the surname now ; first letter of surname in capital letter ; rest of the letters in small ; printing surname ; Driver Code
using System ; class Initials { public static void printInitials ( string str ) { int len = str . Length ; str = str . Trim ( ) ; String t = " " ; for ( int i = 0 ; i < len ; i ++ ) { char ch = str [ i ] ; if ( ch != ' ▁ ' ) { t = t + ch ; } else { Console . Write ( Char . ToUpper ( t [ 0 ] ) + " . ▁ " ) ; t = " " ; } } string temp = " " ; for ( int j = 0 ; j < t . Length ; j ++ ) { if ( j == 0 ) temp = temp + Char . ToUpper ( t [ 0 ] ) ; else temp = temp + Char . ToLower ( t [ j ] ) ; } Console . WriteLine ( temp ) ; } public static void Main ( ) { string str = " ishita ▁ bhuiya " ; printInitials ( str ) ; } }
Count of strings that can be formed from another string using each character at | C # program to print the number of times str2 can be formed from str1 using the characters of str1 only once ; Function to find the number of str2 that can be formed using characters of str1 ; iterate and mark the frequencies of all characters in str1 ; find the minimum frequency of every character in str1 ; Driver Code
using System ; class GFG { static int findNumberOfTimes ( String str1 , String str2 ) { int [ ] freq = new int [ 26 ] ; int l1 = str1 . Length ; int [ ] freq2 = new int [ 26 ] ; int l2 = str2 . Length ; for ( int i = 0 ; i < l1 ; i ++ ) { freq [ str1 [ i ] - ' a ' ] += 1 ; } for ( int i = 0 ; i < l2 ; i ++ ) { freq2 [ str2 [ i ] - ' a ' ] += 1 ; } int count = int . MaxValue ; for ( int i = 0 ; i < l2 ; i ++ ) { if ( freq2 [ str2 [ i ] - ' a ' ] != 0 ) count = Math . Min ( count , freq [ str2 [ i ] - ' a ' ] / freq2 [ str2 [ i ] - ' a ' ] ) ; } return count ; } public static void Main ( ) { String str1 = " foreeksgekseg " ; String str2 = " geeks " ; Console . Write ( findNumberOfTimes ( str1 , str2 ) ) ; } }
String transformation using XOR and OR | C # program to check if string1 can be converted to string2 using XOR and OR operations ; function to check if conversion is possible or not ; if lengths are different ; iterate to check if both strings have 1 ; to check if there is even one 1 in string s1 ; to check if there is even one 1 in string s2 ; if both strings have only '0' ; if both string do not have a '1' . ; Driver code
using System ; class GFG { static bool solve ( String s1 , String s2 ) { bool flag1 = false , flag2 = false ; if ( s1 . Length != s2 . Length ) return false ; int l = s1 . Length ; for ( int i = 0 ; i < l ; i ++ ) { if ( s1 [ i ] == '1' ) flag1 = true ; if ( s2 [ i ] == '1' ) flag2 = true ; if ( flag1 == true && flag2 == true ) return true ; } if ( ! flag1 && ! flag2 ) return true ; return false ; } public static void Main ( ) { String s1 = "100101" ; String s2 = "100000" ; if ( solve ( s1 , s2 ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Smallest alphabet greater than a given character | C # Program to find the smallest character from the given set of letter , which is greater than the target element ; Returns the smallest character from the given set of letters that is greater than K ; Take the first element as l and the rightmost element as r ; if this while condition does not satisfy simply return the first element . ; Return the smallest element ; Driver Code ; Function call
using System ; class GFG { static char nextGreatestAlphabet ( char [ ] alphabets , char K ) { int n = alphabets . Length ; if ( K >= alphabets [ n - 1 ] ) return alphabets [ 0 ] ; int l = 0 , r = alphabets . Length - 1 ; int ans = - 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( alphabets [ mid ] > K ) { ans = mid ; r = mid - 1 ; } else l = mid + 1 ; } return alphabets [ ans ] ; } public static void Main ( ) { char [ ] letters = { ' A ' , ' r ' , ' z ' } ; char K = ' z ' ; char result = nextGreatestAlphabet ( letters , K ) ; Console . Write ( result ) ; } }
Longest substring of 0 s in a string formed by k concatenations | C # code to find maximum length of substring that contains only 0 's ; Function to calculate maximum length of substring containing only zero ; loop to first calculate longest substring in string ; if all elements in string are '0' ; Else , find size of prefix and suffix containing only zeroes ; Calculate prefix containing only zeroes ; Calculate suffix containing only zeroes ; if k <= 1 then there is no need to take prefix + suffix into account ; Driver code
using System ; class GFG { public static int subzero ( String s , int k ) { int ans = 0 , curr = 0 ; int len = s . Length ; char [ ] str = s . ToCharArray ( ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( str [ i ] == '0' ) curr ++ ; else curr = 0 ; ans = Math . Max ( ans , curr ) ; } if ( ans == len ) return len * k ; else { int pre = 0 , suff = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) pre ++ ; else break ; } for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == '0' ) suff ++ ; else break ; } if ( k > 1 ) ans = Math . Max ( ans , pre + suff ) ; return ans ; } } public static void Main ( ) { String str = "00100110" ; int k = 5 ; Console . Write ( subzero ( str , k ) ) ; } }
Find nth term of the Dragon Curve Sequence | C # code to find nth term of the Dragon Curve Sequence ; function to generate the nth term ; first term ; generating each term of the sequence ; loop to generate the ith term ; add character from the original string ; add alternate 0 and 1 in between ; if previous added term was '0' then add '1' ; now current term becomes previous term ; if previous added term was '1' , then add '0' ; now current term becomes previous term ; s becomes the ith term of the sequence ; Driver Code ; Taking inputs ; generate nth term of dragon curve sequence ; Printing output
using System ; class GFG { static String Dragon_Curve_Sequence ( int n ) { String s = "1" ; for ( int i = 2 ; i <= n ; i ++ ) { String temp = "1" ; char prev = '1' , zero = '0' , one = '1' ; for ( int j = 0 ; j < s . Length ; j ++ ) { temp += s [ j ] ; if ( prev == '0' ) { temp += one ; prev = one ; } else { temp += zero ; prev = zero ; } } s = temp ; } return s ; } public static void Main ( ) { int n = 4 ; String s = Dragon_Curve_Sequence ( n ) ; Console . WriteLine ( s ) ; } }
Number of substrings of a string | C # program to count number of substrings of a string ; Driver Code
using System ; class GFG { static int countNonEmptySubstr ( string str ) { int n = str . Length ; return n * ( n + 1 ) / 2 ; } public static void Main ( ) { string s = " abcde " ; Console . Write ( countNonEmptySubstr ( s ) ) ; } }
Count substrings with each character occurring at most k times | C # program to count number of substrings in which each character has count less than or equal to k . ; variable to store count of substrings . ; array to store count of each character . ; Initialize all characters count to zero . ; increment character count ; check only the count of current character because only the count of this character is changed . The ending point is incremented to current position only if all other characters have count at most k and hence their count is not checked . If count is less than k , then increase ans by 1. ; if count is less than k , then break as subsequent substrings for this starting point will also have count greater than k and hence are reduntant to check . ; return the final count of substrings . ; Driver code
using System ; class GFG { public static int findSubstrings ( string s , int k ) { int ans = 0 ; int [ ] cnt = new int [ 26 ] ; int i , j , n = s . Length ; for ( i = 0 ; i < n ; i ++ ) { Array . Clear ( cnt , 0 , cnt . Length ) ; for ( j = i ; j < n ; j ++ ) { cnt [ s [ j ] - ' a ' ] ++ ; if ( cnt [ s [ j ] - ' a ' ] <= k ) ans ++ ; else break ; } } return ans ; } public static int Main ( ) { string S = " aaabb " ; int k = 2 ; Console . WriteLine ( findSubstrings ( S , k ) ) ; return 0 ; } }
Check if characters of one string can be swapped to form other | C # program to check if characters of one string can be swapped to form other ; if length is not same print no ; Count frequencies of character in first string . ; iterate through the second string decrement counts of characters in second string ; Since lengths are same , some value would definitely become negative if result is false . ; Driver Code
using System ; class GFG { static int MAX = 26 ; static bool targetstring ( string str1 , string str2 ) { int l1 = str1 . Length ; int l2 = str2 . Length ; if ( l1 != l2 ) return false ; int [ ] map = new int [ MAX ] ; Array . Clear ( map , 0 , 26 ) ; for ( int i = 0 ; i < l1 ; i ++ ) map [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) { map [ str2 [ i ] - ' a ' ] -- ; if ( map [ str2 [ i ] - ' a ' ] < 0 ) return false ; } return true ; } static void Main ( ) { string str1 = " geeksforgeeks " ; string str2 = " geegeeksksfor " ; if ( targetstring ( str1 , str2 ) ) Console . Write ( " YES " ) ; else Console . Write ( " NO " ) ; } }
Find the Number which contain the digit d | C # program to print the number which contain the digit d from 0 to n ; Returns true if d is present as digit in number x . ; Breal loop if d is present as digit ; If loop broke ; function to display the values ; Check all numbers one by one ; checking for digit ; Driver code
using System ; class GFG { static bool isDigitPresent ( int x , int d ) { while ( x > 0 ) { if ( x % 10 == d ) break ; x = x / 10 ; } return ( x > 0 ) ; } static void printNumbers ( int n , int d ) { for ( int i = 0 ; i <= n ; i ++ ) if ( i == d || isDigitPresent ( i , d ) ) Console . Write ( i + " ▁ " ) ; } public static void Main ( ) { int n = 47 , d = 7 ; printNumbers ( n , d ) ; } }
Find one extra character in a string | C # program to find extra character in one string ; store string values in map ; store second string in map with frequency ; store first string in map with frequency ; if the frequency is 1 then this character is which is added extra ; Driver code ; given string ; find Extra Character
using System ; class GFG { static char findExtraCharcter ( char [ ] strA , char [ ] strB ) { int [ ] m1 = new int [ 256 ] ; for ( int i = 0 ; i < strB . Length ; i ++ ) m1 [ strB [ i ] ] ++ ; for ( int i = 0 ; i < strA . Length ; i ++ ) m1 [ strA [ i ] ] -- ; for ( int i = 0 ; i < m1 . Length ; i ++ ) { if ( m1 [ i ] == 1 ) return ( char ) i ; } return char . MinValue ; } public static void Main ( String [ ] args ) { String strA = " abcd " ; String strB = " cbdad " ; Console . WriteLine ( findExtraCharcter ( strA . ToCharArray ( ) , strB . ToCharArray ( ) ) ) ; } }
Find one extra character in a string | C # program to find extra character in one string ; result store the result ; traverse string A till end and xor with res ; xor with res ; traverse string B till end and xor with res ; xor with res ; print result at the end ; Driver Code ; given string
using System ; class GFG { static char findExtraCharcter ( string strA , string strB ) { int res = 0 , i ; for ( i = 0 ; i < strA . Length ; i ++ ) { res ^= strA [ i ] ; } for ( i = 0 ; i < strB . Length ; i ++ ) { res ^= strB [ i ] ; } return ( ( char ) ( res ) ) ; } public static void Main ( ) { string strA = " abcd " ; string strB = " cbdad " ; Console . WriteLine ( findExtraCharcter ( strA , strB ) ) ; } }
Find one extra character in a string | C # program to find extra character in one string ; Determine String with extra character . ; Add character codes of both the strings ; Add last character code of large String . ; Minus the character code of smaller string from the character code of large string . The result will be the extra character code . ; Driver code
using System ; class GFG { private static char findExtraCharacter ( String s1 , String s2 ) { String smallStr ; String largeStr ; if ( s1 . Length > s2 . Length ) { smallStr = s2 ; largeStr = s1 ; } else { smallStr = s1 ; largeStr = s2 ; } int smallStrCodeTotal = 0 ; int largeStrCodeTotal = 0 ; int i = 0 ; for ( ; i < smallStr . Length ; i ++ ) { smallStrCodeTotal += smallStr [ i ] ; largeStrCodeTotal += largeStr [ i ] ; } largeStrCodeTotal += largeStr [ i ] ; int intChar = largeStrCodeTotal - smallStrCodeTotal ; return ( char ) intChar ; } public static void Main ( String [ ] args ) { String s1 = " abcd " ; String s2 = " cbdae " ; char extraChar = findExtraCharacter ( s1 , s2 ) ; Console . WriteLine ( " Extra ▁ character : ▁ " + extraChar ) ; } }
Function to copy string ( Iterative and Recursive ) | Iterative C # Program to copy one String to another . ; Function to copy one string to other assuming that other string has enough space . ; Driver code
using System ; class GFG { static void myCopy ( char [ ] s1 , char [ ] s2 ) { int i = 0 ; for ( i = 0 ; i < s1 . Length ; i ++ ) s2 [ i ] = s1 [ i ] ; } public static void Main ( String [ ] args ) { char [ ] s1 = " GEEKSFORGEEKS " . ToCharArray ( ) ; char [ ] s2 = new char [ s1 . Length ] ; myCopy ( s1 , s2 ) ; Console . WriteLine ( String . Join ( " " , s2 ) ) ; } }