logo
down
shadow

vb.net reading text file ,split to random range


vb.net reading text file ,split to random range

By : nisvet
Date : November 21 2020, 01:01 AM
I hope this helps you . I want to read List's text line into a random range from 2 to 5 line and save to link. , Here's a simple example:
code :
    Dim R As New Random
    Dim Count As Integer
    Dim RangeLength As Integer
    Dim DataFileName As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "test.txt")
    Dim Links As New List(Of List(Of String))
    Using SR As New System.IO.StreamReader(DataFileName)
        While Not SR.EndOfStream
            Count = 0
            RangeLength = R.Next(2, 6)
            Dim curLinkSet As New List(Of String)
            Links.Add(curLinkSet)
            While Not SR.EndOfStream AndAlso Count < RangeLength
                curLinkSet.Add(SR.ReadLine)
                Count = Count + 1
            End While
        End While
    End Using

    For i As Integer = 0 To Links.Count - 1
        Debug.Print("Set #" & i)
        Dim LinkSet As List(Of String) = Links(i)
        For x As Integer = 0 To LinkSet.Count - 1
            Debug.Print(x & ": " & LinkSet(x))
        Next
        Debug.Print("")
    Next
Set #0
0: aa
1: bb
2: cc

Set #1
0: dd
1: ee
2: ff
3: gg
4: hh

Set #2
0: ii
1: yy
2: tt
3: rr

Set #3
0: ee
1: ww
2: qq
3: uu

Set #4
0: oo
1: pp


Share : facebook icon twitter icon
Reading random lines from a text file into a JLabel

Reading random lines from a text file into a JLabel


By : g.p
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Why not read in all the questions when the application starts, store them in some collection, and then just grab a random one when you need it? Much easier than trying to read the file each time.
Reading in a text file in a set line range

Reading in a text file in a set line range


By : Maurice Beretta Gart
Date : March 29 2020, 07:55 AM
it helps some times You can use itertools.islice() on the file object and use iteration to read only specific lines:
code :
import itertools

with open(file_to_save, "r") as text_file:
    for line in itertools.islice(text_file, 19, 52):
         # do something with line
reading hex from text file and split it in c program

reading hex from text file and split it in c program


By : Reece Davies
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further hexa[1] and hexa[2] are characters, but you're printing them as though they were strings, that is, character arrays. Since they're in the range 0-255, and this range of memory is inaccessible, you get a crash.
Do this:
code :
printf("\n first digit= %c \n", hexa[1]);
How to sub split when reading from text file

How to sub split when reading from text file


By : Ponkux
Date : March 29 2020, 07:55 AM
Does that help Rather a little bit confused , At first, split line using delimiter ",":
code :
String line = "FooBoo,male,20,10/04/1988";
String[] parts = line.split(",");
String dob = parts[parts.length - 1];
String[] sDob = dob.split("/");
for (String s : sDob) {
    System.out.println(s);
}
ArrayList<String> sDobList = new ArrayList<>(Arrays.asList(sDob));
Split text and select random from text file

Split text and select random from text file


By : leaboy
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a text file where each passage of text is separated by ### , You can start by splitting the text with the ### string as delimeter:
code :
String [] textParts = text.split("###");
Random rand = new Random();
int  randomIndex = rand.nextInt(textParts.length());
String randomTextPart = textParts[randomIndex];
Related Posts Related Posts :
  • Search and replace with regex including lookbehinds does not work in VS2017
  • How to Quit or Close (not Kill) Word document (process)?
  • Parsing string with nested separators
  • How to invoke a DLL method from PowerShell 1.0
  • Starting Web Api 2 with OWIN
  • display a string with multiple lines in TextBox
  • Is it possible to programmatically get a shared Dropbox link without sending the user to the dropbox login page?
  • HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\TimeZoneKeyName corrupt?
  • Performance cost of creating array of constants as function argument
  • SQL Server rowversion and order
  • Type.GetType returns null when called via COM interop
  • Is the Microsoft.Practices.EnterpriseLibrary.Validation outdated?
  • .net Bitmap changes color of image
  • LINQ Join with same Name on different tables
  • Programmatically share a dropbox link in .net without having user login to Dropbox
  • bootstrapper fails to install .Net Framework 4.0
  • Why would signing credentials from a RSA-SHA512 X509Certificate2 appear to be RSA-SHA256?
  • Using .NET Class as the DataSource with SSRS RDLC
  • Choosing SQL Server version for new project
  • WCF FileNotFoundException
  • Fullcalendar ignoring all options on initialization?
  • Freebase oAuth2 Bad Request(400) .Net
  • Why does InlineCollection not offer an Indexer (without casting)?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org