Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

beschäftige mich gerade mit C# und möchte, das eine Eingabe so bearbeitet wird, das jeder Anfangsbuchstabe groß geschrieben wird.

Das bei einem Satz, bzw. bei der Eingabe von mehreren Wörtern die Wörter einzeln erkannt werden, habe ich bereits hinbekommen (mit str.Split) und entsprechenden Trennzeichen.

Kann mir vielleicht jemand einen Denkanstoß geben?

Vielen Dank! :)


private List<String> ConvertFirst2UpperCase(List<String> words)

{

     char[] word;

     List<String> first2Upper = new List<String>();

     for (int i = 0; i < words.Count; i++)

     {

          word = new char[words[i].Length];

          word = words[i].ToCharArray(); //(char[])words[i];

          word[0] = Convert.ToChar((word[0].ToString()).ToUpper());

          first2Upper.Add(Convert.ToString(word));

     }

     return first2Upper;

}

So müßte es klappen, mußt natürlich deine gefüllte Liste mit Worten als den Parameter übergeben.

So in etwa (Nicht getestet!):


string phrase = "The quick brown fox jumps over the lazy dog";

string[] words = phrase.Split(new char[] { ' ' });

for(int i = 0; i < words.Length; ++i) {

 string word = words[i];

 words[i] = word[0].ToUpper() + word.Substring(1);

}

phrase = string.Join(" ", words);

Grüße, JasonDelife.

Funktionert wunderbar!

Ich frage mich allerdings, wie man auf den Namespace kommen soll, um auf die ensprechende Methode zu kommen.

Letzendlich führen bekanntlich viele Wege ans Ziel.

Ich bedanke mich bei Euch :)

Hallo JasonDelife,

bei der angegebenen Lösung erscheint die Fehlermeldung:

Fehler 2 Keine Überladung für die ToUpper-Methode nimmt 0 Argumente an.
So richtig schlau bin ich daraus nicht geworden. Kannst Du mir vielleicht erklären,was da schief läuft?
So in etwa (Nicht getestet!):

string phrase = "The quick brown fox jumps over the lazy dog";

string[] words = phrase.Split(new char[] { ' ' });

for(int i = 0; i < words.Length; ++i) {

 string word = words[i];

 words[i] = word[0].ToUpper() + word.Substring(1);

}

phrase = string.Join(" ", words);

Grüße, JasonDelife.

Vielen Dank und noch nen schönen Sonntag :)

public List<String> ConvertFirstToUpper(List<String> text)

        {

            for (int i = 0; i < text.Count; i++)

            {

                text[i] = text[i][0].ToString().ToUpper() + text[i].ToString().Substring(1);

            }

            return text;

        }

Vielen vielen Dank an alle, die in diesem Thread geholfen haben.

jetzt müsste man ihn nur noch als gelöst markieren können :floet:

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.