Solved

c# string

Posted on 2016-10-07
6
64 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Industry Leaders: 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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

729 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