Jump to content
Xtreme .Net Talk

themster

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by themster

  1. When checking for prime you only need to check to the sqrt of the possible prime. This will speed up the testing even more. The time you save increases rapidly when testing large numbers. For count = 2 to Sqrt(currentNumber) ... Next Take for example the number 1000000. Testing up to sqrt of the number will be 500 times faster then testing up to half the number. (1000000/2)/Sqrt(1000000)=500.
  2. Is it a bad idea to write it in .NET? What other language would you recommend then, C?
  3. I'm trying to write a emulator for a processor called RCx8. Do anyone know of a good tutorial on processor emulating or emulators in general? What I need is a tutorial that includes the logical steps in creating an emulator. I'm also looking for a tutorial for creating a virtual memory for my emulator.
  4. Is there any way that I can create a public function in my class that is called And. I get an understandable error saying that And is a reserved word. Is there any way around this problem? In the System.Collections.BitArray class they use And as a function name. How do they do that?
  5. I might be me, but I can't use substring to replace chars within strings like I can with mid. I have tried to use Insert but it doesn't seem to replace, it only inserts new chars.
  6. I found the following code but the buffer doesn't return anything. Dim myStreamReader As StreamReader = New StreamReader( _ New FileStream("C:\somefile.txt", FileMode.Open), _ System.Text.Encoding.Unicode, False, 4096) Dim cBuffer() As Char ReDim cBuffer(4096) Do While myStreamReader.ReadBlock(cBuffer, 0, cBuffer.Length - 1) > 0 'Buffer filled and available for use Loop myStreamReader.Close()
  7. By using a parser you can build a regular expression from the template. The template symbol * equals \w* in regex and ? equals \w. Then try this: Dim Template As String Dim Pattern As String Dim SearchString As String Dim FoundMatch As Boolean Dim i As Integer Dim r As Regex Template = "*cd?f*" SearchString = "abcdefg" For i = 0 To Len(Template) - 1 Select Case Template.Substring(i, 1) Case "*" Pattern = Pattern + "\w*" Case "?" Pattern = Pattern + "\w" Case Else Pattern = Pattern + Template.Substring(i, 1) End Select Next FoundMatch = r.IsMatch(SearchString, Pattern) In this case the regex pattern becomes \w*cd\wf\w* and the string matches the template.
  8. I'm currently working on a modul for a crypto tool and I'm having some problems. The modul is supposed to be able to match word by the use of a mask consisting of letters. For exemple should the mask 'abb' match the words 't ree' and 's upp ose'. So far I have written a parser that generates a regex patttern. The mask 'abba' becomes the pattern '(\w)(\w)\2\1'. So far so good. The problem arises when I use a mask similar to the following, 'abcd'. This mask matches 'cats' but also 'room' because of the fact that '\w' matches any letter. In other words, I want that two letters in the mask are two different letters in the match. For exemple can't both 'b' and 'c' match 'o' (see the 'room' example). I have tried to solve the problem by using this pattern instead, '(\w)([^\1])([^\1\2])([^\1\2\3])'. The problem is that regex doesn't seem to be able to replace the '\1' with the first group ('(\w)') when the '\1' is inside '[]'. Is there any to solve this problem? I haven't worked much with regex so it's possible that there are functions within regex which will solve the problem.
  9. I want to read textfiles as large as 100000 lines and I want it go as fast as possible. I have tried using StreamReader.ReadLine and that works fine for textfiles with 20000 lines which takes approx. 3-4 sec. When I use the same code on a textfile with 40000 lines it doesn't take 6-8 sec but 20-25 sec. Why isn't the time proportional to the number of lines and is there any other faster way to read files?
  10. Imports You need to import the namespace that includes the Left function. Include this first in your code, before any declaration. Imports Txt = Microsoft.VisualBasic.Strings You can then use the following syntax to access the Left function. Txt.Left("testing,2) You can you the Object Browser to search for the function you are looking for and then include the required namespace using Imports.
×
×
  • Create New...