Título: eliminar registros con ceros
Publicado por: luis456 en 12 Noviembre 2014, 08:09 am
Hola como puedo eliminar los registros que contengan ceros ? 00, 01, 02, 04, 05, 06 00, 01, 03, 04, 05, 06 00, 01, 04, 05, 06, 08 00, 01, 04, 05, 06, 09 00, 01, 04, 05, 06, 18 00, 01, 04, 05, 06, 10 00, 01, 04, 05, 06, 11 00, 01, 04, 05, 06, 15 10 ,20 ,45 ,88 .87, 90 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim combinations As New List(Of List(Of Integer)) Dim length As Integer = 5 Dim skipStart As Integer = 0 Do Until skipStart = (constantValues.Count - length) Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length) Dim count As Integer = 0 Do Until count = (constantValues.Count - length - skipStart) Dim list As List(Of Integer) = values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList list.Sort() combinations.Add(list) ' Debug.WriteLine(String.Join(", ", values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToArray)) count += 1 Loop ' count = (constantValues.Count - length) skipStart += 1 Loop ' skipStart = (constantValues.Count - length) combinations.ForEach(Sub(combination As List(Of Integer)) ListBox2.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString))) End Sub) End Sub
Luis
Título: Re: eliminar registros con ceros
Publicado por: Eleкtro en 12 Noviembre 2014, 10:17 am
Intenta explicarte de forma precisa... ¿tienes una lista de números y quieres eliminar los números que contengan "0"? Dim list As New List(Of Integer) From {0, 1, 10, 100, 2, 3, 4, 5} list.RemoveAll(Function(n As Integer) CStr(n).Contains(0)) MsgBox(String.Join(", ", list))
Saludos
Título: Re: eliminar registros con ceros
Publicado por: luis456 en 12 Noviembre 2014, 10:47 am
Si pero los doble cero adelante :) siempre me explico mal ;(
00, 01, 02, 04, 05, 06 <---- eliminar toda la linea que contengan doble cero o cero de primeros los demas tipo 01 05 09 dejarlos
00, 01, 03, 04, 05, 06 =eliminar 00, 01, 04, 05, 06, 08 =eliminar 00, 01, 04, 05, 06, 09 =eliminar
01, 02, 04, 05, 06, 18 =<--dejar 10 ,20 ,45 ,88 .87, 90 <----dejar
luis
Título: Re: eliminar registros con ceros
Publicado por: Eleкtro en 12 Noviembre 2014, 12:07 pm
No hay "doble cero" Luis, son "0" sin más, ni tampoco "01" etc, recuerda que estás usando una lista numérica, no de String, el resto de ceros los añades (de forma "temporal") solamente para mostrarlos en el listbox con ese formato de ceros. combinations.ForEach(Sub(combination As List(Of Integer)) ListBox2.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString)))
Así que puedes comprobar si el primer elemento de cada sub-lista es "0", eliminar la sub-lista, y ya está: Public Class Form1 Private Sub test() Handles MyBase.Shown ' instancio la lista que contiene las sub-listas Dim lists As New List(Of List(Of Integer)) ' instancio las sub-listas Dim list1 As New List(Of Integer) From {0, 1, 3, 4, 5, 6} Dim list2 As New List(Of Integer) From {0, 1, 4, 5, 6, 8} Dim list3 As New List(Of Integer) From {0, 1, 4, 5, 6, 9} Dim list4 As New List(Of Integer) From {1, 2, 4, 5, 6, 18} Dim list5 As New List(Of Integer) From {10, 20, 45, 88, 87, 90} ' añado las sub-listas lists.AddRange({list1, list2, list3, list4, list5}) ' elimino las sub-listas cuyo primer elemento sea "0" lists.RemoveAll(Function(list As List(Of Integer)) list.First = 0) ' Compruebo las listas que han quedado... Dim sb As New System.Text.StringBuilder For Each list As List(Of Integer) In lists sb.AppendLine(String.Join(", ", list)) Next MessageBox.Show(sb.ToString, "Listas que no se han eliminado", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub End Class
Deberías verte capaz de hacer el resto de modificaciones en caso de que necesite modificaciones para tus necesidades, simplemente puedes repetir esta instrucción con la condición que quieras comprobar: lists.RemoveAll(Function(list As List(Of Integer)) list.First = 0)
lists.RemoveAll(...list.Contains(0)...), por ejemplo... también puedes añadirle los "0" de forma temporal para crear esa condición y evaluarla, de la mimsma manera que en el código que cité donde añades los "0". saludos
Título: Re: eliminar registros con ceros
Publicado por: luis456 en 12 Noviembre 2014, 12:22 pm
Corro a probar y enredarme mas jejejej :huh:
gracias Elektro
Luis
Título: Re: eliminar registros con ceros
Publicado por: luis456 en 12 Noviembre 2014, 12:35 pm
Tiempo record ,,, ni yo me lo creo ;D FUNCIONA Loop ' skipStart = (constantValues.Count - length) combinations.RemoveAll(Function(list As List(Of Integer)) list.First = 0) combinations.ForEach(Sub(combination As List(Of Integer)) ListBox2.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString))) End Sub)
Gracias elektro Luis
|