Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

c# string

Posted on 2016-10-07
6
Medium Priority
?
71 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 32

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 32

Expert Comment

by:Pawan Kumar
ID: 41834649
Let me check it again..
0
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!

 
LVL 32

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 83

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 32

Accepted Solution

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

604 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