Found 34488 Articles for Programming

Write a C# program to check if a number is Palindrome or not

Samual Sam
Updated on 20-Jun-2020 09:11:43

848 Views

First, find the reverse of the string to check if a string is a palindrome or not −Array.reverse()Now use the equals() method to match the original string with the reversed. If the result is true, that would mean the string is Palindrome.Let us try the complete example. Here, our string is “Madam”, which is when reversed gives the same result −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          string string1, rev;          string1 = "Madam";          char[] ch = string1.ToCharArray(); ... Read More

Clone() method in C#

karthikeya Boyini
Updated on 20-Jun-2020 09:12:10

597 Views

The Clone() method in C# is used to create a similar copy of the array.Let us see an example to clone an array using the Clone() method −Example Live Demousing System; class Program {    static void Main() {       string[] arr = { "one", "two", "three", "four", "five" };       string[] arrCloned = arr.Clone() as string[];       Console.WriteLine(string.Join(", ", arr));       // cloned array       Console.WriteLine(string.Join(", ", arrCloned));       Console.WriteLine();    } }Outputone, two, three, four, five one, two, three, four, fiveAbove, we have a string array −string[] ... Read More

Comments in C#

Samual Sam
Updated on 20-Jun-2020 09:13:35

151 Views

Comments are used for explaining the code. Compilers ignore the comment entries. The multiline comments in C# programs start with /* and terminate with the characters */ as shown below.Multi-line comments/* The following is a multi-line comment In C# /*The /*...*/ is ignored by the compiler and it is put to add comments in the program.Single line comments// variable int a = 10;The following is a sample C# program showing how to add single-line as well as multi-line comments −Example Live Demousing System; namespace HelloWorldApplication {    class HelloWorld {       static void Main(string[] args) {     ... Read More

Classes vs Structures in C#

Samual Sam
Updated on 20-Jun-2020 09:26:22

575 Views

In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.When you define a class, you define a blueprint for a data type.The following are the differences between classes and structures in C# −Classes are reference types and structs are value typesUnlike classes, structures cannot inherit other structures or classes.Structures cannot be used as a base for other structures or classes.When you create a struct object using the New operator, it gets created and the appropriate constructor ... Read More

Class in C#

karthikeya Boyini
Updated on 20-Jun-2020 09:45:26

124 Views

Blueprint for a data type is what you can call a class in C#. Objects are instances of a class. The methods and variables that constitute a class are called members of the class.ExampleThe following is the general form of a class in C# − class class_name {    // member variables     variable1;     variable2;    ...     variableN;    // member methods     method1(parameter_list) {       // method body    }     method2(parameter_list) {       // method body    }    ...     methodN(parameter_list) {       ... Read More

Python Program to replace a word with asterisks in a sentence

Sarika Singh
Updated on 23-Nov-2022 08:07:48

2K+ Views

The use of the symbol * (asterisks) in writing or printing as a reference mark, a sign that some letters or words have been omitted, a way to indicate a possible but unproven linguistic form, or for other arbitrary purposes. In this article we will discuss different ways to replace a word with asterisks in a sentence in Python. Input-Output Scenarios Following is an input and its output scenario of replacing a word in a sentence with asterisks − Input: Welcome to the TutorialsPoint family. Output: Welcome to the TutorialsPoint ****** We can see in the above scenario that ... Read More

Map function and Lambda expression in Python to replace characters

Samual Sam
Updated on 20-Jun-2020 09:08:20

446 Views

We want to replace a character a1 with a character a2 and a2 with a1. For example, For the input string, "puporials toinp"and characters p and t, we want the end string to look like −"tutorials point"For this we can use map function and lambdas to make the replacement. The map(lambda, input) function iterates over each item passed to it(in form of iterable input) and apply the lambda expression to it. So we can use it as follows −Example Live Demodef replaceUsingMapAndLambda(sent, a1, a2): # We create a lambda that only works if we input a1 or a2 and swaps them. ... Read More

Map function and Dictionary in Python to sum ASCII values

karthikeya Boyini
Updated on 20-Jun-2020 09:09:09

589 Views

We want to calculate the ASCII sum for each word in a sentence and the sentence as a whole using map function and dictionaries. For example, if we have the sentence −"hi people of the world"The corresponding ASCII sums for the words would be : 209 645 213 321 552And their total would be : 1940.We can use the map function to find the ASCII value of each letter in a word using the ord function. Then using the sum function we can sum it up. For each word, we can repeat this process and get a final sum of ... Read More

Remove all duplicates from a given string in Python

Samual Sam
Updated on 20-Jun-2020 09:10:40

455 Views

To remove all duplicates from a string in python, we need to first split the string by spaces so that we have each word in an array. Then there are multiple ways to remove duplicates.We can remove duplicates by first converting all words to lowercase, then sorting them and finally picking only the unique ones. For example, Examplesent = "Hi my name is John Doe John Doe is my name" # Seperate out each word words = sent.split(" ") # Convert all words to lowercase words = map(lambda x:x.lower(), words) # Sort the words in order words.sort() ... Read More

Tokenize text using NLTK in python

karthikeya Boyini
Updated on 20-Jun-2020 08:27:52

692 Views

Given a character sequence and a defined document unit, tokenization is the task of chopping it up into pieces, called tokens, perhaps at the same time throwing away certain characters, such as punctuation. In the context of nltk and python, it is simply the process of putting each token in a list so that instead of iterating over each letter at a time, we can iterate over a token.For example, given the input string −Hi man, how have you been?We should get the output −['Hi', 'man', ', ', 'how', 'have', 'you', 'been', '?']We can tokenize this text using the word_tokenize ... Read More

Advertisements