Public Shared Function String2Hex(input As String) As String ' "-", " ", etc
Return String.Join(" ", (From c In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)), 16)).ToArray).ToUpper()
End Function
Date :
2013-05-06 07:25:30
By :
ผ่านมา
No. 3
Guest
C# ดูอิ่มอุ่นกว่า VB
Code (C#)
public string String2Hex(string input) // " ", "-", etc
{
return String.Join(" ", (from c in input.ToCharArray()
select Convert.ToString(c, 16))).ToUpper();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Random_String_Generator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public String generateRandomString(int length)
{
//Initiate objects & vars Random random = new Random();
String randomString = "";
int randNumber = 10;
Random rd = new Random();
//Loop ‘length’ times to generate a random number or character
for (int i = 0; i < length; i++)
{
if (rd.Next(1, 3) == 1)
randNumber = rd.Next(97, 123);
//char {a-z}
else
randNumber = rd.Next(48, 58);
//int {0-9}
//append random char or digit to random string
randomString = randomString + (char)randNumber;
}
//return the random string
return randomString;
}
public String generateRandomNumber(int length)
{
//Initiate objects & vars Random random = new Random();
String randomString = "";
int randNumber = 0;
Random rd = new Random();
//Loop ‘length’ times to generate a random number or character
for (int i = 0; i < length; i++)
{
// if (rd.Next(1, 3) == 1)
//randNumber = rd.Next(97, 123);
//char {a-z}
// else
randNumber = rd.Next(48, 58);
//int {0-9}
//append random char or digit to random string
randomString = randomString + (char)randNumber;
}
//return the random string
return randomString;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = "CET" + generateRandomString(int.Parse(textBox2.Text));
textBox3.Text = generateRandomNumber(int.Parse(textBox4.Text));
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
}
}