Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 5 of 2544
Split String with Comma (,) in Java
Let’s say the following is our string.String str = " This is demo text, and demo line!";To split a string with comma, use the split() method in Java.str.split("[,]", 0);The following is the complete example.Examplepublic class Demo { public static void main(String[] args) { String str = "This is demo text, and demo line!"; String[] res = str.split("[,]", 0); for(String myStr: res) { System.out.println(myStr); } } }OutputThis is demo text and demo line!
Read MoreHow to check if a C/C++ string is an int?
There are several methods to check that string is an int or not and one of those method is to use isdigit() to check the string.Here is an example to check whether a string is an int or not in C++ language,Example#include #include using namespace std; int main() { char str[] = "3257fg"; for (int i = 0; i < strlen(str); i++) { if(isdigit(str[i])) cout
Read MoreHow to find the first character of a string in C#?
To get the first character, use the substring() method.Let’s say the following is our string −string str = "Welcome to the Planet!";Now to get the first character, set the value 1 in the substring() method.string res = str.Substring(0, 1);Let us see the complete code −Exampleusing System; public class Demo { public static void Main() { string str = "Welcome to the Planet!"; string res = str.Substring(0, 1); Console.WriteLine(res); } }OutputW
Read MoreHow to find the index of an item in a C# list in a single step?
To get the index of an item in a single line, use the FindIndex() and Contains() methods.int index = myList.FindIndex(a => a.Contains("Tennis"));Above, we got the index of an element using the FindIndex(), which is assisted by Contains() method for that specific element.Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List () { "Football", "Soccer", "Tennis", }; // finding index int index = myList.FindIndex(a => a.Contains("Tennis")); // displaying index Console.WriteLine("List Item Tennis Found at index: " + index); } }OutputList Item Tennis Found at index: 2
Read MoreAdd key-value pair in C# Dictionary
To add key-value pair in C# Dictionary, firstly declare a Dictionary.IDictionary d = new Dictionary();Now, add elements with KeyValuePair.d.Add(new KeyValuePair(1, "TVs")); d.Add(new KeyValuePair(2, "Appliances")); d.Add(new KeyValuePair(3, "Mobile"));After adding elements, let us display the key-value pair.Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary d = new Dictionary(); d.Add(new KeyValuePair(1, "TVs")); d.Add(new KeyValuePair(2, "Appliances")); d.Add(new KeyValuePair(3, "Mobile")); d.Add(new KeyValuePair(4, "Tablet")); d.Add(new KeyValuePair(5, "Laptop")); d.Add(new KeyValuePair(6, "Desktop")); d.Add(new KeyValuePair(7, "Hard Drive")); ...
Read MoreC# Program to check if a number is prime or not
To calculate whether a number is prime or not, we have used a for loop. Within that on every iteration, we use an if statement to find that the remainder is equal to 0, between the number itself.for (int i = 1; i
Read MoreHow to pop the first element from a C# List?
To pop the first element in the list, use the RemoveAt() method. It eliminates the element from the position you want to remove the element.Set the listList myList = new List() { "Operating System", "Computer Networks", "Compiler Design" };Now pop the first element using RemoveAt(0)myList.RemoveAt(0);Let us see the complete example.Exampleusing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { List myList = new List() { "Operating System", "Computer Networks", "Compiler Design" }; ...
Read MoreArray Copy in Java
Array in Java can be copied to another array using the following ways.Using variable assignment. This method has side effects as changes to the element of an array reflects on both the places. To prevent this side effect following are the better ways to copy the array elements.Create a new array of the same length and copy each element.Use the clone method of the array. Clone methods create a new array of the same size.Use System.arraycopy() method. The arraycopy() can be used to copy a subset of an array.ExampleCreate a java class named Tester.Tester.javapublic class Tester { public static ...
Read MoreHow to read inputs as integers in C#?
To read inputs as integers in C#, use the Convert.ToInt32() method.res = Convert.ToInt32(val);Let us see how −The Convert.ToInt32 converts the specified string representation of a number to an equivalent 32-bit signed integer.Firstly, read the console input −string val; val = Console.ReadLine();After reading, convert it to an integer.int res; res = Convert.ToInt32(val);Let us see an example −Exampleusing System; using System.Collections.Generic; class Demo { static void Main() { string val; int res; Console.WriteLine("Input from user: "); val = Console.ReadLine(); // convert to ...
Read MoreC# Program to Convert Integer to String
To convert an integer to string in C#, use the ToString() method.Set the integer for which you want the string −int num = 299;Use the ToString() method to convert Integer to String −String s; int num = 299; s = num.ToString();ExampleYou can try to run the following code to convert an integer to string in C# −using System; class MyApplication { static void Main(string[] args) { String s; int num = 299; s = num.ToString(); Console.WriteLine("String = "+s); Console.ReadLine(); } }OutputString = 299
Read More