Solved

c# string

Posted on 2016-10-07
6
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 28

Expert Comment

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

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

Author Comment

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

Expert Comment

by:Pawan Kumar
ID: 41834649
Let me check it again..
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:Pawan Kumar
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 81

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 28

Accepted Solution

by:
Pawan Kumar 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Suggested Courses

732 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