Tuesday, March 9, 2021

, , , ,

Substring function in r programming

 Substring() function in R can be used to extract the characters present in the data or to manipulate the given data.

 You can easily extract the required characters from a string and  Substring() in r can also replace the values in a string.

Syntax for substring r :-

substr(x,start,stop)
substring(x,first,last=1000000L)

 Here we can do so many things with substring function in r link extracting of values, replacement of values etc.

    x =  input data / file.
    Start / First= starting index of the given substring.
    Stop / Last= Ending index of the substring.

r extract substring :-

#returns the characters from 1,11
df<-("computer_dev_private_limited")
substring(df,1,11)

OUTPUT : - 

"computer_de"

We hope you understand how to r extract part of the data from the given string.

r replace substring with program : -

#returns the string by replacing the _ by space
df<-("We are_developers")
substring(df,7,7)=" "
df


Output = “We are developers”

Put the same value to replace the values in a string with the help of
 Substring() function in R.

String replacement using substring() function with multiple value :-

#replaces the 4th letter of each string by $
df<-c("Alok","Joseph","Hayato","Kelly","Paloma","Moca")
substring(df,4,4)<-c("$")
df


Output = “Alo$” “Jos$ph” “Hay$to” “Kel$y” “Pal$ma” “Moc$”

Here the 4th letter in the given strings replaced by the "$" sign with the help of substring r.

Learn to use of str_sub() and substr() function in R :-

 well r programming is used to create the data in the form od row or colums.

With the help of given example you can learn to add data in existing data with the help of substr() function in R.

Example for substr() in r : -

#creates the data frame
df<-data.frame(Technologies=c("Datascience","machinelearning","Deeplearning","Artificalintelligence"),Popularity=c("70%","85%","90%","95%"))
df

OUTPUT : - 

OUTPUT
OUTPUT

Example for str_sub() function in R

#using the str_sub function
df$Extracted_Technologies=str_sub(df$Technologies,10,15)
> df

substring r
substr in r


Saturday, March 6, 2021

, , , , ,

Example program for isxdigit() function in c

 The isxdigit() function in c programming checks whether a character is a hexadecimal digit character (0-9, a-f, A-F) or not.

Syntax for isxdigit in c :-

int isxdigit( int arg );

 isxdigit() Parameters

The isxdigit() in c takes a single character as it's parameter.

 C isxdigit() Return Value

 if passed argument is an hexadecimal character then isxdigit() return non-zero integer otherwise return 0.

Example program for C isxdigit() function


#include <ctype.h>
#include <stdio.h>

int main() {
   char c = '5';
   int result;

   // hexadecimal character is passed
   result = isxdigit(c); // result is non-zero
   printf("Result when %c is passed to isxdigit(): %d", c, isxdigit(c));

   c = 'M';

   // non-hexadecimal character is passed
   result = isxdigit(c); // result is 0

   printf("\nResult when %c is passed to isxdigit(): %d", c, isxdigit(c));

   return 0;
}

OUTPUT : - 



C isxdigit()
C isxdigit()

, , ,

Example program for isspace() in c

 The isspace() function in c programming used to check whether a character is a white-space character or not.

It return the non-zero integer if given argument to the isspace() in c is a white-space character, otherwise return 0.

Syntax For isspace() function in c: -

int isspace(int argument);

First check out the List of all white-space characters in C programming are:

isspace in c
Check white-space character


Example program for Check white-space character


#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    int result;

    printf("Enter a character: ");
    scanf("%c", &c);
    
    result = isspace(c);

    if (result == 0)
    {
        printf("Not a white-space character.");
    }
    else
    {
        printf("White-space character.");
    }

    return 0;
}


, , , , ,

Example program for ispunct in c

 The ispunct() function in c programming checks whether a character is a punctuation mark or not.

Syntax for ispunct() in c

int ispunct(int argument);

it returns a non-zero integer if given characters to ispunct() in c is an punctuation otherwise return 0.

Example for Program to check punctuation with the help of ispunct() function in c:-

#include <stdio.h>
#include <ctype.h>

int main() {
   char c;
   int result;

   c = ':';
   result = ispunct(c);

   if (result == 0) {
      printf("%c is not a punctuation", c);
   } else {
      printf("%c is a punctuation", c);
   }

   return 0;
}

 Output

ispunct
ispunct in c

 

 

, , , ,

Example program for isprint() in c

 The isprint() function in c programming is used to check the given character is a printable character or not.

Printable characters in c programming are just the opposite of control characters and these type of characters checked using iscntrl() function in c.

Syntax for isprint() in c

int isprint( int arg );

for return value if the given characters passed to isprint() function in c is a printable character then it return non-zero integer otherwise return zero.

isprint() in c takes argument in the form of integer and returns.

Example for C isprint() function

 

#include <ctype.h>
#include <stdio.h>

int main()
{
    char c;

    c = 'Q';
    printf("Result when a printable character %c is passed to isprint(): %d", c, isprint(c));

    c = '\n';
    printf("\nResult when a control character %c is passed to isprint(): %d", c, isprint(c));

    return 0;
}

 OUTPUT : - 

C isprint()
C isprint() function in c

 

Monday, March 1, 2021

, , , ,

Example program for isgraph in c

 The isgraph() function in c use to checks that given character is a graphic character or not.

What is graphic character:- Characters which have graphical representation are call as graphic characters. 

isgraph in c return the non zero integer if passed argument is an 
graphic character otherwise returns 0.

Syntax for isgraph in c 

int isgraph(int argument);

 Example program to Check graphic character with help of isgraph in c

 

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    int result;

    c = ' ';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d\n", c, result);

    c = '\n';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d\n", c, result);

    c = '9';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d\n", c, result);  

 OUTPUT : -

When   is passed to isgraph() = 0
When 
 is passed to isgraph() = 0
When 9 is passed to isgraph() = 1
, , , ,

Example program for iscntrl() function in c

  •   iscntrl() function in c Used to check if the given character is a control character or not.
  • Characters that are not print on the screen are known as control characters for exam newline.
  •  If a character passed by iscntrl() function is a  control character then it  return non zero integer value otherwise return 0. 
  •   iscntrl() C is define in ctype.h header file.
  • this function  takes a single argument and returns an integer.


Syntax for iscntrl() in c :-

int iscntrl(int argument);

Example program for iscntrl() in c : -

 

#include <stdio.h>
#include <ctype.h>

int main()
{
    char c;
    int result;

    c = 'Q';
    result = iscntrl(c);
    printf("When %c is passed to iscntrl() = %d\n", c, result);

    c = '\n';
    result = iscntrl(c);
    printf("When %c is passed to iscntrl() = %d", c, result);

    return 0;
}

 OUTPUT : -

When Q is passed to iscntrl() = 0
When 
 is passed to iscntrl() = 1