• Log in or sign up for an account here: https://www.sythe.org/login

C# Library (For People From VB.net)

  • Thread starter Thread starter Skeletron
  • Start date Start date
S

Skeletron

Guest
Are you sick and tired of VB.net having functions like Asc, StrReverse, IsNumeric that C# does not have.

Well, this is what I use in C# that is the same as those functions but created 100% by me. When I moved to C# I noticed that most of the functions like these old Com components that are still incorporated in VB.net were not anywhere on C#. So, best thing I had to do is to built them my self.

These functions are extremely fast; much faster then the VB.net's one's.

public static string Asc(string String)
{
try
{
string Compile = "";
int ascvalue;
char chr;
System.Collections.ArrayList ListItems = new System.Collections.ArrayList();
for (int I = 0; I < String.Length; I++)
{
ListItems.Add(Convert.ToString(String.Substring(I, 1)));
chr = Convert.ToChar(ListItems);
ascvalue = (int)chr;
Compile = Compile + ascvalue;
}
return Compile;
}
catch
{
return;
}
}

public static bool IsNumeric(string ValidString)
{
try
{
Int32.Parse(ValidString);
}
catch
{
return false;
}
return true;
}

public static string StrReverse(string UnReversed)
{
System.Collections.ArrayList Items = new System.Collections.ArrayList();
String Part;
String Compile = "";
for (int I = 0; I < UnReversed.Length; I++)
{
Part = Convert.ToString(UnReversed.Substring(I, 1));
Items.Add(Part);
}
Items.Reverse();
for (int X = 0; X < Items.Count; X++)
{
Compile = Compile + Convert.ToString(Items[X]);
}
return Compile;
}
public static bool Kill(string FileName)
{
try
{
System.IO.File.Delete(FileName);
}
catch
{
return false;
}
return true;
}
public static string Chr(string AscString)
{
try
{
int AscInt;
Char chr;
AscInt = Convert.ToInt32(AscString);
chr = Convert.ToChar(AscInt);
return Convert.ToString(chr);
}
catch
{
return;
}
}


I have not had time to finish up the Chr in here that operates with Asc but the Chr function for now only support one letter.

Hopefully these can be used in your programs.

~Skeletron
 
Two Factor Authentication User
Some of you methods could be much shorter.
For example, you can get the ascii value of a character using the following
Code:
// For characters
int AsciiValue1 = (int)'d';
//or for strings
int AsciiValue2 = (int)"d"[0];
You can also get characters from their ascii value using this:
Code:
char Character = (char)97;
 
Yeah I know that but the Chr in here pretty much works with the way that the Asc works but this Chr turns the Asc value into a valid Chr.

The Chr that is incorporated into the C# Namespace works fine though if you want to use that one.

But then again, I still have to finish up it for full compatibility.

And the Asc value is meant to take a long string like Asc("Hello") and convert it into a line of Asc values. For it to convert back into a Chr value I will have to sit down with it after school and finish it up since it can only support 1 Chr.

Oh and also, 'ascvalue = (int)'d';', that is in there.

Timing is fast, I tested it with a stopwatch and it did a long string like "sdgsgsggbnggntn" to a Asc in 0ms.

Much faster then the one in the VB name space because it calls it from a .dll and is actually not included into the .net framework.
 
Runescape Gamblingrunescape gambling
Back
Top