473,385 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Replace the 1st Character in every word

I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an uppercase.
Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to do
it in .net with the .substring and .toupper methods.

--
All replies are appreciated.
Thanks in advance.
JrMc
Nov 18 '05 #1
5 1737
The easiest suggestion I could make it so split off a space make the first
letter caps, then rejoin adding the space back. This probably isn't the
most performant way to handle this, so don't use this in a tight loop, but
it does show some of the built in string functions and char arrays.

bill

string s = "hello world, dot net rocks!";
string [] sa = s.Split( ' ' );
string word = null;
for( int i = 0 ; i < sa.Length ; i++ )
{
word = sa[i];
char [] letters = word.ToCharArray();
if ( letters.Length > 0 )
{
letters[0] = Char.ToUpper( letters[0] );
}
word = new string( letters );
sa[i] = word;
}
s = String.Join( " ", sa );
Console.Write( s );
"JrMc" <Jr**@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an uppercase. Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to do it in .net with the .substring and .toupper methods.

--
All replies are appreciated.
Thanks in advance.
JrMc

Nov 18 '05 #2

Hi.

string original = "horse";

string result = original.Substring(0,1).ToUpper()+original.Remove( 0,1);
"JrMc" <Jr**@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an
uppercase.
Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to
do
it in .net with the .substring and .toupper methods.

--
All replies are appreciated.
Thanks in advance.
JrMc

Nov 18 '05 #3
Thank you so much. Works like a champ.

jrmc

"Kikoz" wrote:

Hi.

string original = "horse";

string result = original.Substring(0,1).ToUpper()+original.Remove( 0,1);
"JrMc" <Jr**@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an
uppercase.
Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to
do
it in .net with the .substring and .toupper methods.

--
All replies are appreciated.
Thanks in advance.
JrMc


Nov 18 '05 #4
Even though i cannot understand you want to do that here is a sample.

string str = "horse";
string newstr = str.Replace(str.Substring(0,1),str.Substring(0,1). ToUpper());

"JrMc" <Jr**@discussions.microsoft.com> wrote in message news:<9E**********************************@microso ft.com>...
I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an uppercase.
Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to do
it in .net with the .substring and .toupper methods.

Nov 18 '05 #5
string orig="a horse is a horse";
string
capped=System.Globalization.CultureInfo.InvariantC ulture.TextInfo.ToTitleCase(orig);

"JrMc" wrote:
I am new to this .net environement. I'm needing to do a simple task - I
need to read the first character of a word and replace it with an uppercase.
Example:

"horse" --> change to "Horse"

I can do this on an as/400 using RPG, but cannot figure out the syntax to do
it in .net with the .substring and .toupper methods.

--
All replies are appreciated.
Thanks in advance.
JrMc

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: - ions | last post by:
Hi, i would like to know how to replace every char in a string with a certin given char using the String.replace(char oldChar,char newChar). I would like to replace all letters with an underscore...
4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
6
by: Aaron | last post by:
If i use the replace function in c# string a = "this"; a.replace("is", "something"); my output would be like thsomething how can i replace when only the whole word matches. string a =...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
14
by: Etu | last post by:
Hi, I have a string: string c = "'abc' \"cde\", 'mno' \"xyz\","; how can I use the c.Replace(???, ???) method to have this string: "'abc' "cde", 'mno' "xyz"," that is, all the...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
12
by: implement | last post by:
Hi all! I try to code my own version of replace but it doesn't work. I hope somebody can help me out. It only replaces the first char!. Why I don't use the public string.replace function?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.