K kostefar Active Member Licensed User Longtime User May 4, 2018 #1 Dear All, The result of: Code: Dim l As List l.Initialize l.Add("77 a") l.Add("88 a") l.Add("880 a") l.Add("777 a") l.Sort(True) For i = 0 To l.Size - 1 Log (l.Get(i)) Next .. is Code: 77 a 777 a 88 a 880 a and I want it to be Code: 77 a 88 a 777 a 888 a It works if I don´t add the numbers as text, but in this case I need to have some text showing in each list item after the number. Any hints? Thanks in advance! Last edited: May 4, 2018
Dear All, The result of: Code: Dim l As List l.Initialize l.Add("77 a") l.Add("88 a") l.Add("880 a") l.Add("777 a") l.Sort(True) For i = 0 To l.Size - 1 Log (l.Get(i)) Next .. is Code: 77 a 777 a 88 a 880 a and I want it to be Code: 77 a 88 a 777 a 888 a It works if I don´t add the numbers as text, but in this case I need to have some text showing in each list item after the number. Any hints? Thanks in advance!
LucaMs Expert Licensed User Longtime User May 4, 2018 #2 Add zeroes ("0") on the left, to have all items with the same lenght. When you must show them, you can remove the useless zeroes. [I remember that many "0" must be write "zeroes"; is this correct? ] Upvote 0
Add zeroes ("0") on the left, to have all items with the same lenght. When you must show them, you can remove the useless zeroes. [I remember that many "0" must be write "zeroes"; is this correct? ]
K kostefar Active Member Licensed User Longtime User May 4, 2018 #3 LucaMs said: Add zeroes ("0") on the left, to have all items with the same lenght. When you must show them, you can remove the useless zeroes. [I remember that many "0" must be write "zeroes"; is this correct? ] Click to expand... I think I get you, so padding 0´s .. if largest number expected is 1000, then you´d add 3 zeros to anything below 10, 2 to anything below 100 etc? EDIT: Yup, did the trick: Code: If pct < 10 Then pctstring = "000" & pct If pct > 10 And pct < 100 Then pctstring = "00" & pct If pct > 100 And pct < 1000 Then pctstring = "0" & pct ranklist.Add (pctstring & " " & coin) And afterwards Code: Dim rankitem As String = ranklist.get(i) If rankitem.StartsWith("000") Then rankitem = rankitem.SubString(3) If rankitem.StartsWith("00") Then rankitem = rankitem.SubString(2) If rankitem.StartsWith("0") Then rankitem = rankitem.SubString(1) Log ("# " & i & " " & rankitem) Last edited: May 4, 2018 Upvote 0
LucaMs said: Add zeroes ("0") on the left, to have all items with the same lenght. When you must show them, you can remove the useless zeroes. [I remember that many "0" must be write "zeroes"; is this correct? ] Click to expand... I think I get you, so padding 0´s .. if largest number expected is 1000, then you´d add 3 zeros to anything below 10, 2 to anything below 100 etc? EDIT: Yup, did the trick: Code: If pct < 10 Then pctstring = "000" & pct If pct > 10 And pct < 100 Then pctstring = "00" & pct If pct > 100 And pct < 1000 Then pctstring = "0" & pct ranklist.Add (pctstring & " " & coin) And afterwards Code: Dim rankitem As String = ranklist.get(i) If rankitem.StartsWith("000") Then rankitem = rankitem.SubString(3) If rankitem.StartsWith("00") Then rankitem = rankitem.SubString(2) If rankitem.StartsWith("0") Then rankitem = rankitem.SubString(1) Log ("# " & i & " " & rankitem)
LucaMs Expert Licensed User Longtime User May 4, 2018 #4 LucaMs said: [I remember that many "0" must be write "zeroes"; is this correct? ] Click to expand... You can use both; since I'm old, I will use "zeroes" Upvote 0
LucaMs said: [I remember that many "0" must be write "zeroes"; is this correct? ] Click to expand... You can use both; since I'm old, I will use "zeroes"
LucaMs Expert Licensed User Longtime User May 4, 2018 #5 kostefar said: I think I get you, so padding 0´s .. if largest number expected is 1000, then you´d add 3 zeros to anything below 10, 2 to anything below 100 etc? Click to expand... Yes Upvote 0
kostefar said: I think I get you, so padding 0´s .. if largest number expected is 1000, then you´d add 3 zeros to anything below 10, 2 to anything below 100 etc? Click to expand... Yes
LucaMs Expert Licensed User Longtime User May 4, 2018 #6 It is like "right alignment" of a text but not in a string with spaces, with zeroes. Upvote 0
udg Expert Licensed User Longtime User May 4, 2018 #7 Have a look at the List's SortType method Upvote 0
LucaMs Expert Licensed User Longtime User May 4, 2018 #8 udg said: Have a look at the List's SortType method Click to expand... Io si, conosco. Molto utile. I know. Very useful. Upvote 0
udg said: Have a look at the List's SortType method Click to expand... Io si, conosco. Molto utile. I know. Very useful.
K kostefar Active Member Licensed User Longtime User May 4, 2018 #9 udg said: Have a look at the List's SortType method Click to expand... Wow, that´s a nice approach indeed. Came across sort-type before but didnt look into it. Very elegant! Thanks! Upvote 0
udg said: Have a look at the List's SortType method Click to expand... Wow, that´s a nice approach indeed. Came across sort-type before but didnt look into it. Very elegant! Thanks!