Solved

c# string

Posted on 2016-10-07
6
39 Views
Last Modified: 2016-10-07
I have a name John Smith
and I want to have format as jsmith

How can I do that in c#?

Thanks
0
Comment
Question by:ITsolutionWizard
  • 4
6 Comments
 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
ID: 41834642
Try.. sorry could not test..now..

STRING str = "John Smith"
String newstr  = SUBSTRING (str,1) + SUBSTRING(str,INDEXOF(' '), LEN(str) - INDEXOF(' ') )
0
 

Author Comment

by:ITsolutionWizard
ID: 41834647
sorry not working
0
 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
ID: 41834649
Let me check it again..
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
ID: 41834652
//Your code goes here
            String str = "John Smith";
            String newstr  =   str.Substring(0,1) + str.Substring(str.Length-str.IndexOf(' ')-1);
            Console.WriteLine (newstr);

Ouput

JSmith
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41834659
using System;

namespace rr_28975164
{
    class Program
    {
        static void Main(string[] args)
        {
            string Fullname = "John Smith";
            string result;
            string first;
            string last;
            string[] names = Fullname.Split(' ');
            first = names[0][0].ToString();
            last = names[1];
            string output = first + last;
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }
}

Open in new window

0
 
LVL 18

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
ID: 41834660
If needed entire code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Pawan
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
            String str = "John Smith";
            String newstr  =   str.Substring(0,1) + str.Substring(str.Length-str.IndexOf(' ')-1);
            Console.WriteLine (newstr);
        }
    }
}

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now