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.

Ist Inhalt von CString alphanummerisch oder nummerisch ...

Empfohlene Antworten

Veröffentlicht

Servus,

ich möchte überprüfen ob der Inhalt eines CStrings nur Ziffern enthält oder auch

auch andere Zeiche enthalten sind.

Bisher prüfe ich jedes Zeichen in dem String, ich frage mich aber ob es keine

schnellere bzw. kürzere und einfachere Methode gibt.

Was am ende dabei herauskommen soll wäre ist:

bool isStringNummeric(CString);

wie gesagt, ich habe eine Lösung, aber es kann ja sein das jemand das

ganze schon einmal kurz gelöst hat.

TinTin

Bisher prüfe ich jedes Zeichen in dem String, ich frage mich aber ob es keine

schnellere bzw. kürzere und einfachere Methode gibt.

Was soll an deiner Methode kompliziert sein?

Ich wuerde nun auch ueber den String iterieren und per isdigit() jedes Zeichen pruefen.

Goos

hab grade mal was gemacht:

bool isStringNumeric(CString csStr)

{

	int j = csStr.GetLength() ;

	int l = -1;

	bool bRet = true;

	if (j > 0)

	{

		for (int k=0;k<j;k++)

		{

			char chr = csStr.GetAt(k);

			l = isdigit(chr);

			if (l == 0)

			{	

				bRet = false;

			}

		}

	}

	else

	{

		bRet = false;

	}

	return bRet;

}

Kurz Zwischenfrage an Klotzkopp:

int j = csStr.GetLength();

for( int i = 0; i < j; ++i )

Sollte das nicht am Ende abstürzen, da i == csStr.GetLength()? :confused:

Warum so umständlich?

Stimmt, warum so umständlich. Der String ist ja schon nicht mehr nummerisch

wenn isdigit() einmal false ist.

naja, war ja nur ein erster versuch, bevor das mit dem isdigit kam war die

Funktion noch schlimmer...aber vergesen wir das, heute war sowieso nicht mein

Tag -> anderer Thread mit dem Debugger.

EDIT:

csStr.GetLenght() < 1 sollte meiner meinung nach schon abgefangen werden, sonnst

ist bei einem leeren String der Returnwert dennoch true und das stimmt ja nun nicht.

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.