We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, February 19, 2025

To find and print the digram (a pair of consecutive characters) that appears the most in a given string using C#.

Print the digram which appears maximum number of times in a string
A digram is a sequence of 2 consecutive characters
I/o - "asddaaasadedadaddasasasasas"
O/P - "as"


using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string input = "asddaaasadedadaddasasasasas";

        Dictionary<string, int> digramCount = new Dictionary<string, int>();

        // Count all digrams in the string
        for (int i = 0; i < input.Length - 1; i++)
        {
            string digram = input.Substring(i, 2);

            if (digramCount.ContainsKey(digram))
                digramCount[digram]++;
            else
                digramCount[digram] = 1;
        }

        // Find the digram with maximum occurrences
        var maxDigram = digramCount.OrderByDescending(x => x.Value).First();

        Console.WriteLine($"\"{maxDigram.Key}\" appears {maxDigram.Value} times");
    }
}

Wednesday, February 12, 2025

Routing in Angular

1. What is Routing in Angular?

Routing allows you to navigate between views (components) in your Angular application using the URL. It manages:

  • Browser navigation

  • Lazy loading of modules/components

  • Parameter passing via URLs


2. Basic Routing Setup

app.routes.ts (Angular 15+ standalone routing)


import { Routes } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component'; export const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'about', component: AboutComponent } ];

main.ts

import { bootstrapApplication } from '@angular/platform-browser'; import { AppComponent } from './app/app.component'; import { provideRouter } from '@angular/router'; import { routes } from './app/app.routes'; bootstrapApplication(AppComponent, { providers: [provideRouter(routes)], });

 3. Using RouterOutlet

app.component.html

html
<h1>Angular 19 Routing</h1> <router-outlet></router-outlet>

This acts as a placeholder where routed components will render.


4. Navigation with Links

html
<a routerLink="/">Home</a> <a routerLink="/about">About</a>

Or programmatically:

ts

import { Router } from '@angular/router'; constructor(private router: Router) {} goToAbout() { this.router.navigate(['/about']); }

5. Route Parameters

Define route with params:

ts
{ path: 'user/:id', component: UserComponent }

Access it in UserComponent:

ts

import { ActivatedRoute } from '@angular/router'; constructor(private route: ActivatedRoute) {} ngOnInit() { const id = this.route.snapshot.paramMap.get('id'); }

6. Lazy Loading with Standalone Components

Angular 15+ and Angular 19 make it easy to lazy load even standalone components:

ts

{ path: 'lazy', loadComponent: () => import('./lazy/lazy.component').then(m => m.LazyComponent) }

7. Route Guards (Optional)

Example for AuthGuard:

ts
{ path: 'admin', component: AdminComponent, canActivate: [AuthGuard] }

8. Wildcard and Redirects

ts

{ path: '', redirectTo: 'home', pathMatch: 'full' }, { path: '**', component: PageNotFoundComponent }

Sunday, June 20, 2021

How to convert Alphabet to next one alphabet like input "ab" and output will be "bc"

 class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine(LetterChanges(Console.ReadLine()));

            Console.ReadLine();
        }

        public static string LetterChanges(string str)
        {
            string newString = "";

            char[] chr = str.ToCharArray();
            for (int i = 0; i < chr.Length; i++)
            {
                var chr1 = chr[i];
                bool result = chr1.ToString().All(x => char.IsLetter(x));
                if(result)
                {
                    char chr2 = (char)((int)chr1 + 1);

                    newString += chr2;
                }
                else
                {
                    char chr2 = (char)((int)chr1);

                    newString += chr2;
                }
             
            }
           return newString;

        }
    }

Output