Find Matching Substring Using Regular Expression in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Our string is − string str = " My make "; Use the following regular expression to find the substring “make” @"\bmake\b" Here is the complete code − Example Live Demo using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); ... Read More

Database Operations in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

The most common databases used in C# are Microsoft SQL Server and Oracle. The following is done to work with databases. Connect Set the Database Name, Optional Parameters and Credentials. The username and password is needed to set a connection to the database. The connection string would look somewhat like this. private static string _connectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=test;Application Name=Demo;Connection Timeout2w00"; Above, the Application Name is Demo. Select Statement To fetch data from the database, the SELECT statement is used Insert The INSERT command is used to insert data in the database. Update The database ... Read More

Functional Interfaces in Java Programming

Fendadis John
Updated on 30-Jul-2019 22:30:23

490 Views

Functional interfaces have a single functionality to exhibit. For example, a Comparable interface with a single method 'compareTo' is used for comparison purpose. Java 8 has defined a lot of functional interfaces to be used extensively in lambda expressions. Following is the list of functional interfaces defined in java.util.Function package. Given below is the list of interfaces in Java8. Sr.No. Interface & Description 1 BiConsumer Represents an operation that accepts two input arguments, and returns no result. 2 BiFunction Represents a function that accepts two arguments and produces a result. ... Read More

Prevent Cloning to Break Singleton Class Pattern in Java

Rishi Raj
Updated on 30-Jul-2019 22:30:23

325 Views

A Singleton pattern states that a class can have a single instance and multiple instances are not permitted to be created. For this purpose, we make the constructor of the class a private and return a instance via a static method. But using cloning, we can still create multiple instance of a class. See the example below − Example - Breaking Singleton Live Demo public class Tester{ public static void main(String[] args) throws CloneNotSupportedException { A a = A.getInstance(); ... Read More

Cohesion in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Cohesion in C# shows the relationship within modules. It shows the functional strength of the modules. The greater the cohesion, the better will be the program design. It is the dependency between the modules internal elements like methods and internal modules. High cohesion will allow you to reuse classes and method. An example of High cohesion can be seen in System.Math class i.e.it has Mathematical constants and static methods − Math.Abs Math.PI Math.Pow A class that does a lot of things at a time is hard to understand and maintain. This is what we call low cohesion and ... Read More

Find Length of Largest Consecutive 1's in Binary Representation of a Given String

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

468 Views

Given the number, find length of the longest consecutive 1's in its binary representation. Example Input: n = 15 Output: 4 The binary representation of 14 is 1111. Algorithm Step 1: input the number. Step 2: use one counter variable c=0. Step 3: Count the number of iterations to reach i = 0. Step 4: This operation reduces length of every sequence of 1s by one. Example code # Python program to find # length of the longest # consecutive 1s in # binary representation of a number. def maxlength(n): # ... Read More

Check if Binary Representation is Palindrome in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

852 Views

Here we use different python inbuilt function. First we use bin() for converting number into it’s binary for, then reverse the binary form of string and compare with originals, if match then palindrome otherwise not. Example Input: 5 Output: palindrome Explanation Binary representation of 5 is 101 Reverse it and result is 101, then compare and its match with originals. So its palindrome Algorithm Palindromenumber(n) /* n is the number */ Step 1: input n Step 2: convert n into binary form. Step 3: skip the first two characters of a string. Step 4: them reverse the ... Read More

Python Boolean Operations

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

444 Views

The basic Boolean operations are and, or, not operations. The and operation − The basic syntax of and operation is: x and y. It indicates that when the x is false, then return x, otherwise returns y. The or operation −The basic syntax of or operation is: x or y. It indicates that when the x is false, then return y, otherwise returns x. The not operation − The basic syntax of and operation is: not x. It indicates that when the x is false, then it returns true, otherwise it returns false. Example Code Live ... Read More

Math Class Methods in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

519 Views

The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Class Declaration Following is the declaration for java.lang.Math class − public final class Math extends Object Field Following are the fields for java.lang.Math class − static double E − This is the double value that is closer than any other to e, the base of the natural logarithms. static double PI − This is the double value that is closer than any other to pi, the ratio of the circumference of a circle ... Read More

Covariance and Contravariance in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

315 Views

To deal with classes effectively, use the concept of covariance and contra variance. Let us consider the following as our class. One is a base class for class Two, whereas Two is a base class for Three. class One { } class Two: One { } class Three : Two { } A base class can hold a derived class, but the opposite is not possible. With Covariance, you can pass a derived type where a base type is expected. Co-variance can be used on array, interface, delegates, etc in C#. Contra variance is for parameters. ... Read More

Advertisements