Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
c# string abbreviation
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
/* * C# Program to Display the Abbreviation of a Text */ using System; using System.Collections.Generic; using System.Linq; using System.Text; class abbreviation { string str; public void readdata() { Console.WriteLine("Enter a String :"); str=Console.In.ReadLine(); } public void abbre() { char[] c, result; int j = 0; c = new char[str.Length]; result = new char[str.Length]; c = str.ToCharArray(); result[j++] = (char)((int)c[0] ^ 32); result[j++] = '.'; for (int i = 0; i < str.Length - 1; i++) { if (c[i] == ' ' || c[i] == '\t' || c[i] == '\n') { int k = (int)c[i + 1] ^ 32; result[j++] = (char)k; result[j++] = '.'; } } Console.Write("The Abbreviation for {0} is ", str); Console.WriteLine(result); Console.ReadLine(); class initials { static void printInitials(String name) { if (name.Length == 0) return; // Since touuper() returns int, // we do typecasting Console.Write(Char.ToUpper(name[0])); // Traverse rest of the string and // print the characters after spaces. for (int i = 1; i < name.Length - 1; i++) if (name[i] == ' ') Console.Write(" " + Char.ToUpper(name[i + 1])); } } public static void Main() { abbreviation obj=new abbreviation(); obj.readdata(); obj.abbre(); { String name = "prabhat kumar singh"; printInitials(name); } } }
Show compiler warnings
[
+
]
Show input
edit mode
|
history
|
discussion