C# algorithm function: get the maximum length number in a string
/// <summary> /// Get the longest number of the string/// </summary> /// <param name="inputStr">Input string</param>/// <returns>Longest number</returns>public string GetMaxLenNumber(string inputStr) { //Storing characters in strings into arrays for easy processing char[] strCharArray = (); //The location where to start processing int startPos = 0; //The current character length int tempCharCount = 0; //The length of the number int maxLen = 0; //Total length of array int len = ; int pos = 0; while (startPos < len) { //Temporary maximum length in the loop int tempMax = 0; while (tempCharCount + startPos < len) { //The character to start processing char c = strCharArray[tempCharCount + startPos]; if ((c)) { //If it is a number tempMax++; if (tempMax > maxLen) { maxLen = tempMax; pos = startPos; } } else { //Not a number tempMax = 0; startPos++; break; } tempCharCount++; } if (startPos + tempCharCount == len) { break; } tempCharCount = 0; } string s = (pos, maxLen); return s; }
The above is the entire content of this article. I hope you can give you a reference and I hope you can support me more.
Related Articles
C# code automatic modification solution any file instance under any solution
This article mainly introduces any file instance under the C# code automatic modification solution. Friends who need it can refer to it.2013-11-11C# socket programming udp client implementation code sharing
This article mainly introduces the implementation of the udp client by c# socket programming. Please refer to it and use it.2013-12-12Detailed explanation of how to customize TabControl control styles in WPF
This article mainly introduces you to relevant information about how to customize the TabControl control style of WPF. The article introduces the example code in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2018-04-04Simple implementation method of C# MJPEG client
This article mainly introduces the simple implementation method of C# MJPEG client, helping everyone better understand and learn how to use C#. Interested friends can learn about it.2021-03-03VS2019 The asset file "xxxx\obj\" cannot be found to run NuGet package restore to generate this article
This article mainly introduces VS2019 asset file not found. "xxxx\obj\" runs the NuGet package to restore it to generate this file. This article will share the solution with you. Interested friends, follow the editor to learn together.2020-08-08Exception and continuation processing of C# tasks
This article mainly introduces the exception and continuation processing of C# tasks. The article introduces the example code in detail, which has certain reference learning value for everyone's study or work. If you need it, please learn with the editor below.2023-12-12C# Development WinForm clears data bound to DataGridView control
This article explains in detail how to clear data binding data of WinForm with WinForm, and the example code is introduced in detail. It has certain reference value for everyone's study or work. Friends who need it can refer to it.2022-03-03Unity UGUI's CanvasScaler Canvas Scaler Component Introduction
This article mainly introduces the use of the CanvasScaler canvas scaler component of Unity UGUI. Friends in need can refer to it for reference. I hope it will be helpful. I wish you more progress and an early promotion and salary increase2023-07-07Code that often uses progress bars in C#
Code that often uses progress bars in C#...2007-03-03WinForm implements special effect instances that enable two forms to have activation effects at the same time
This article mainly introduces WinForm implementation of special effects examples that allow two forms to have activation effects at the same time. Based on Windows API, it realizes the special effect of sending messages to another form when activated. It has certain practical value when developing C# projects. Friends who need it can refer to it2014-09-09