Make a method inserting characters into a string in ascending order

xiaoxiao2021-03-06  62

The small downtown, which is done before, you need to create a character index, just a string, each character in the string can be used as an index. This string is also arranged ascended. I look at the right left, I found String There is no sort feature in it. ORRAY is a sort feature. Is I take a character in the string one in an array? I don't want to do it, just write two functions in the tool class. Realization, the code is as follows. Let's refer to it. Mainly use two-point method to realize the location of the location, and then insert it in a suitable location .NameSpace Tools.Module {public class tools {public tools () {}

Public static string getStrfromstr (String src, int index) {if (src.indexof (",") == 0) SRC = src.remove (0, 1); for (int i = 0; i /// calculates the location where a character should be at a descendant sorting string. /// /// String /// character /// The location of this character should public static int GettheSortedIndex (String Str, Char C) { INT ILENGTH = STR.LENGTH; if (ilength == 0) Return 0; if (ilength == 1 && STR [0]> = c) Return 0; else = == 1 && Str [0]

INDEX = ILENGTH / 2; IF (Str [INDEX]> C) {Return GettheSortedIndex (Str.Substring (0, INDEX), C);} else IF (STR [INDEX] /// Insert a character into a paragraph-arranged string /// < / summary> /// To insert characters /// destination string public static void insertcharintosortedString (Char C, Ref string Str) {if (str == null || str.Length == 0) {str = c.toString (); return;} for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-111374.html

New Post(0)