Professional Documents
Culture Documents
C S Check
C S Check
string s = "010120301";
foreach (char c in s)
{
// check if c can be found within s
}
===========
if (x.Contains(c))
{
//// Do Something
}
========
if (Array.IndexOf(x, c) > -1)
{
// The x array contains the character c
}
=========
if(x.Contains(c)) { ... }
========
string input = "A_123000544654654";
string pattern = "[0-9]+";
System.Text.RegularExpressions.Regex.IsMatch(input, pattern);
===============
c lang
/*
* C Program to Check whether a given Character is present in a
* String, Find Frequency & Position of Occurrence
*/
#include <stdio.h>
#include <string.h>
int main()
{
char a, word[50];
int i, freq = 0, flag = 0;
return 0;
}
$ cc charfrequency.c
$ ./a.out
Enter character: r
Now enter the word: programming
Positions of 'r' in programming are: 2 5
Character 'r' occured for 2 times.
===============
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<stdio.h>
#include<conio.h>
#include<math.h>
//bring it in range of 0 to 6
fmonth = fmonth % 7;
return fmonth;
}
//----------------------------------------------
int day_of_week(int date, int month, int year) {
int dayOfWeek;
int YY = year % 100;
int century = year / 100;
//remainder on division by 7
dayOfWeek = dayOfWeek % 7;
switch (dayOfWeek) {
case 0:
printf("weekday = Saturday");
break;
case 1:
printf("weekday = Sunday");
break;
case 2:
printf("weekday = Monday");
break;
case 3:
printf("weekday = Tuesday");
break;
case 4:
printf("weekday = Wednesday");
break;
case 5:
printf("weekday = Thursday");
break;
case 6:
printf("weekday = Friday");
break;
default:
printf("Incorrect data");
}
return 0;
}
//------------------------------------------
int main() {
int date, month, year;
printf("\nEnter the year ");
scanf("%d", &year);
return 0;
}
Output :
1
2
3
4
5
Enter the year 2012
Enter the month 02
Enter the date 29
Date: 29/2/2012
weekday = Wednesday
==============
using System;
namespace Learn
{
class Program
{
static void Main(string[] args)
{
string Str, Revstr = "";
int Length;
Length = Str.Length - 1;
Console.ReadLine();
}
}
}
OUTPUT
-------------
Enter A String : HELLO
Reverse String Is OLLEH
======================
The below program reverses a string using for loop in C#.NET and prints the
output to Console Window.
using System;
namespace ProgramCall
{
class StringReverse
{
static void Main()
{
OUTPUT
------------
Enter A String : PROGRAMCALL.COM
Reverse String Is MOC.LLACMARGORP
=============================
/*
* C# Program to Reverse a String without using Reverse function
*/
using System;
class Program
{
static void Main(string[] args)
{
string Str, reversestring = "";
int Length;
Console.Write("Enter A String : ");
Str = Console.ReadLine();
Length = Str.Length - 1;
while (Length >= 0)
{
reversestring = reversestring + Str[Length];
Length--;
}
Console.WriteLine("Reverse String Is {0}", reversestring);
Console.ReadLine();
}
}
namespace Learn
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a Number");
int numb = int.Parse(Console.ReadLine());
int reverse = 0;
while (numb > 0)
{
int rem = numb % 10;
reverse = (reverse * 10) + rem;
numb = numb / 10;
}
Console.WriteLine("Reverse number={0}", reverse);
Console.ReadLine();
}
}
}
Output
----------
Enter a Number
4567
Reverse number=7654
===============using System;
class myclass
{
static void Main()
{
int fn = 0;
int sn = 1;
int tn = 1;
Console.WriteLine(fn);
Console.WriteLine(sn);
while (true)
{
tn = fn + sn;
if (tn >= 100)
{
break;
}
Console.WriteLine(tn);
fn = sn;
sn = tn;
}
Console.Read();
}
}
Output
0
1
1
2
3
5
8
13
21
34
55
89
===================
Reversing a string using C# for loop
using System;
namespace ProgramCall
{
class StringReverse
{
static void Main()
{
OUTPUT
------------
Enter A String : PROGRAMCALL.COM
Reverse String Is MOC.LLACMARGORP