Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by chrismcrae5712 · Oct 06, 2014 at 12:12 AM · textfieldthanks

Capitalize first letter in Textfield Only?

I am using Regex.Replace to replace anything other A-Z characters. That works perfectly. Now I am just curious as to how do I make it so no matter what the First letter of the string is capitalized and the rest is lower case? I have a textfield with a maximum of 14 characters. Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by meer59 · Nov 30, 2016 at 07:38 AM

Call this and you will get the first letter of the string in upper case.

  string UppercaseFirst(string s)
     {
         if (string.IsNullOrEmpty(s))
         {
             return string.Empty;
         }
         return char.ToUpper(s[0]) + s.Substring(1);
     }


If you want to make it faster performance wise use the method below..

 string UppercaseFirst(string s){
 if (string.IsNullOrEmpty(s))
     {
         return string.Empty;
     }
     char[] a = s.ToCharArray();
     a[0] = char.ToUpper(a[0]);
     return new string(a);
 }
 





Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Carwashh · Jan 31, 2017 at 11:10 AM 0
Share

Thanks for this, I just used it. $$anonymous$$ade a small addition to it though, as I need the first letter capitalised, but the rest lower case.

 string UppercaseFirst(string s){
  if (string.IsNullOrEmpty(s))
      {
          return string.Empty;
      }
      input = input.ToLower();
      char[] a = s.ToCharArray();
      a[0] = char.ToUpper(a[0]);
      return new string(a);
  }

avatar image
0

Answer by Phles · Oct 06, 2014 at 01:26 PM

Hey there, I came up with this quickly it may or may not be just what you're after...

 public static string TidyCase(string sourceStr)
 {
     sourceStr.Trim();
     if (!string.IsNullOrEmpty(sourceStr))
     {
         char[] allCharacters = sourceStr.ToCharArray();
 
         for (int i = 0; i < allCharacters.Length; i++)
         {
             char character = allCharacters[i];
             if (i == 0)
             {
                 if (char.IsLower(character))
                 {
                     allCharacters[i] = char.ToUpper(character);
                 }
             }
             else
             {
                 if (char.IsUpper(character))
                 {
                     allCharacters[i] = char.ToLower(character);
                 }
             }
         }
         return new string(allCharacters);
     }
     return sourceStr;
 }



Hope this helps, Phill

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Yay_For_Humzah · Nov 30, 2016 at 07:38 AM

I do not know the exact syntax for what must be done, but this should be the logic. You can try to select the first letter and then convert it. Look it up to see how it should be done.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by NatCou · Feb 21, 2019 at 11:21 AM

am just adding my solution since the others didn't quite work for what I needed. this capitalises the first letter in the sentence

 private string UpperFirst(string text)
 {
     return char.ToUpper(text[0]) +
         ((text.Length > 1) ? text.Substring(1).ToLower() : string.Empty);
 }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by williamohare · Feb 21, 2019 at 12:37 PM

I was wondering about the same for about a couple of last days. Was trying different methods but none of those were working. Right now, I'm conducting some research for EduBirdie (https://edubirdie.com/paraphrasing-tool) about different techniques in writing in various programmes, and I was curious about the question that was asked above.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ymrasu · Feb 21, 2019 at 12:52 PM 1
Share

A different approach then all the answers this questions post; To make the first letter capitalized while the rest is lower: str = str.Substring(0,1).ToUpper() + str.Substring(1).ToLower();

avatar image catherinederivaledu Ymrasu · Jul 15, 2020 at 12:54 AM 0
Share

Thank you!! ^.^ that worked for me. I had an if-else function that checked to make sure the sentence was valid before altering it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

change font size help - impossible? 1 Answer

Monodevelopement not responding? 2 Answers

Money System 1 Answer

rigidbody2D.velocity.y always returns 0 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges