Initial
This commit is contained in:
parent
cfdfa8eae1
commit
ba8bdb7a04
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.438
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mk0.Tools.Randomization", "Mk0.Tools.Randomization\Mk0.Tools.Randomization.csproj", "{B5391664-66E2-4C4E-BCDA-089B446B9034}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B5391664-66E2-4C4E-BCDA-089B446B9034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B5391664-66E2-4C4E-BCDA-089B446B9034}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B5391664-66E2-4C4E-BCDA-089B446B9034}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B5391664-66E2-4C4E-BCDA-089B446B9034}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {39C91CEC-87C1-438E-BD56-D381D86CFCA9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{B5391664-66E2-4C4E-BCDA-089B446B9034}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Mk0.Tools.Randomization</RootNamespace>
|
||||
<AssemblyName>Mk0.Tools.Randomization</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Randomize.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("Mk0.Tools.Randomization")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Mk0.Tools.Randomization")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019 mk0.at")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("b5391664-66e2-4c4e-bcda-089b446b9034")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// indem Sie "*" wie unten gezeigt eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Mk0.Tools.Randomization
|
||||
{
|
||||
public class Randomize
|
||||
{
|
||||
/// <summary>
|
||||
/// Generiert einen zufälligen String aus Zahlen und Buchstaben mit optionalem Endzeichen
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endzeichen"></param>
|
||||
/// <returns>Zufallsstring</returns>
|
||||
public static string NumbersAndDigits(int length, string beginnzeichen = "", string endzeichen = "")
|
||||
{
|
||||
string ret = string.Empty;
|
||||
StringBuilder SB = new StringBuilder();
|
||||
string Content = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw";
|
||||
Random rnd = new Random();
|
||||
if (beginnzeichen != "")
|
||||
{
|
||||
SB.Append(beginnzeichen);
|
||||
}
|
||||
for (int i = 0; i < length; i++)
|
||||
SB.Append(Content[rnd.Next(Content.Length)]);
|
||||
if (endzeichen != "")
|
||||
{
|
||||
SB.Append(endzeichen);
|
||||
}
|
||||
return SB.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generiert einen zufälligen String Buchstaben mit optionalem Endzeichen
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endzeichen"></param>
|
||||
/// <returns>Zufallsstring</returns>
|
||||
public static string Digits(int length, string beginnzeichen = "", string endzeichen = "")
|
||||
{
|
||||
string ret = string.Empty;
|
||||
StringBuilder SB = new StringBuilder();
|
||||
string Content = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw";
|
||||
Random rnd = new Random();
|
||||
if (beginnzeichen != "")
|
||||
{
|
||||
SB.Append(beginnzeichen);
|
||||
}
|
||||
for (int i = 0; i < length; i++)
|
||||
SB.Append(Content[rnd.Next(Content.Length)]);
|
||||
if (endzeichen != "")
|
||||
{
|
||||
SB.Append(endzeichen);
|
||||
}
|
||||
return SB.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generiert einen zufälligen String aus Zahlen mit optionalem Endzeichen
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endzeichen"></param>
|
||||
/// <returns>Zufallsstring</returns>
|
||||
public static string Numbers(int length, string beginnzeichen = "", string endzeichen = "")
|
||||
{
|
||||
string ret = string.Empty;
|
||||
StringBuilder SB = new StringBuilder();
|
||||
string Content = "1234567890";
|
||||
Random rnd = new Random();
|
||||
if (beginnzeichen != "")
|
||||
{
|
||||
SB.Append(beginnzeichen);
|
||||
}
|
||||
for (int i = 0; i < length; i++)
|
||||
SB.Append(Content[rnd.Next(Content.Length)]);
|
||||
if (endzeichen != "")
|
||||
{
|
||||
SB.Append(endzeichen);
|
||||
}
|
||||
return SB.ToString();
|
||||
}
|
||||
}
|
||||
}
|
23
README.md
23
README.md
|
@ -1 +1,22 @@
|
|||
# Mk0.Tools.Randomization
|
||||
# Mk0.Tools.Randomization
|
||||
(C) 2019 mk0.at
|
||||
|
||||
Allows you to generate a random string with a length of your choice.
|
||||
You can add an optional prefix and an optional appendix to the random string.
|
||||
|
||||
You can use the following methods:
|
||||
|
||||
+ NumbersAndDigits (1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw)
|
||||
+ Digits (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw)
|
||||
+ Numbers (1234567890)
|
||||
|
||||
Example usage:
|
||||
|
||||
Randomize.NumbersAndDigits(5, "_")
|
||||
will return f.e. "_j7Ga9"
|
||||
|
||||
Randomize.Numbers(2, "*", "#")
|
||||
will return f.w. "*59#"
|
||||
|
||||
Randomize.Digits(3)
|
||||
will return f.w. "fOu"
|
Loading…
Reference in New Issue