Merge pull request #2 from Playmaker1210/regex

Regex
This commit was merged in pull request #2.
This commit is contained in:
Playmaker1210
2022-03-22 17:30:47 +01:00
committed by GitHub
47 changed files with 306 additions and 24 deletions

View File

@@ -35,7 +35,17 @@
"ProjectGuid": "f7beeb1c-eb73-42e8-a148-3db8c96b8d56", "ProjectGuid": "f7beeb1c-eb73-42e8-a148-3db8c96b8d56",
"DisplayName": "RekurzivFaktorialis", "DisplayName": "RekurzivFaktorialis",
"ColorIndex": 6 "ColorIndex": 6
},
"b8063178-720e-430c-b364-dc3f1dfce42c": {
"ProjectGuid": "b8063178-720e-430c-b364-dc3f1dfce42c",
"DisplayName": "RegularExpressions",
"ColorIndex": 7
},
"a2fe74e1-b743-11d0-ae1a-00a0c90fffc3": {
"ProjectGuid": "a2fe74e1-b743-11d0-ae1a-00a0c90fffc3",
"DisplayName": "Miscellaneous Files",
"ColorIndex": -1
} }
}, },
"NextColorIndex": 7 "NextColorIndex": 8
} }

Binary file not shown.

View File

@@ -20,6 +20,19 @@ namespace Homerseklet_elemzes {
genMaxHom(); genMaxHom();
} }
public int getEvszak() {
return evszak;
}
public int getHonap() {
return honap;
}
public int getMinHom() {
return min_homerseklet;
}
public int getMaxHom() {
return max_homerseklet;
}
private void genMinHom() { private void genMinHom() {
if (evszak == 1) //tavasz if (evszak == 1) //tavasz
min_homerseklet = random.Next(0, 10); min_homerseklet = random.Next(0, 10);
@@ -47,19 +60,5 @@ namespace Homerseklet_elemzes {
return "Minumum hom: " + min_homerseklet + " maximum hom: " + max_homerseklet return "Minumum hom: " + min_homerseklet + " maximum hom: " + max_homerseklet
+ " atlag hom: " + atlag + "\n"; + " atlag hom: " + atlag + "\n";
} }
public int getEvszak() {
return evszak;
}
public int getHonap() {
return honap;
}
public int getMinHom() {
return min_homerseklet;
}
public int getMaxHom() {
return max_homerseklet;
}
} }
} }

View File

@@ -10,8 +10,47 @@ namespace Homerseklet_elemzes {
Console.WriteLine(napok[index - 1].napi_adatok()); Console.WriteLine(napok[index - 1].napi_adatok());
} }
public static void havi_adat(Nap[] napok, int honap) { public static string havi_adat(Nap[] napok, int honap) {
int min = Int32.MaxValue, max = Int32.MinValue;
float atlag = 0;
for (int i = 0; i < napok.Length; i++) {
if(napok[i].getHonap() == honap) {
if(napok[i].getMinHom() < min) min = napok[i].getMinHom();
if(napok[i].getMaxHom() > max) max = napok[i].getMaxHom();
atlag += (napok[i].getMaxHom() + napok[i].getMinHom()) / 2.0f;
}
}
atlag /= 30.0f;
return "Havi minimum: " + min + " havi maximum: " + max + " havi atlag: " + atlag;
}
public static string evszak_adat(Nap[] napok, int evszak) {
int min = Int32.MaxValue, max = Int32.MinValue;
float atlag = 0;
for (int i = 0; i < napok.Length; i++) {
if (napok[i].getEvszak() == evszak) {
if (napok[i].getMinHom() < min) min = napok[i].getMinHom();
if (napok[i].getMaxHom() > max) max = napok[i].getMaxHom();
atlag += (napok[i].getMaxHom() + napok[i].getMinHom()) / 2.0f;
}
}
atlag /= 90.0f;
return "Evszakban minimum: " + min + " evszakban maximum: " + max + " evszak atlag: " + atlag;
}
public static string eves_adat(Nap[] napok) {
int min = Int32.MaxValue, max = Int32.MinValue;
float atlag = 0;
for (int i = 0; i < napok.Length; i++) {
if (napok[i].getMinHom() < min) min = napok[i].getMinHom();
if (napok[i].getMaxHom() > max) max = napok[i].getMaxHom();
atlag += (napok[i].getMaxHom() + napok[i].getMinHom()) / 2.0f;
}
atlag /= 360.0f;
return "Eves minimum: " + min + " eves maximum: " + max + " eves atlag: " + atlag;
} }
public static void kiir(Nap[] napok) { public static void kiir(Nap[] napok) {
@@ -21,10 +60,10 @@ namespace Homerseklet_elemzes {
} }
static void Main(string[] args) { static void Main(string[] args) {
Nap[] napok = new Nap[360]; Nap[] napok = new Nap[360]; //minden honapra egysegesen 30 napot szamolunk
short honap = 0; short honap = 0;
short evszak = 4; short evszak = 4;
string folytatas = "igen";
for (int i = 0; i < napok.Length; i++) { for (int i = 0; i < napok.Length; i++) {
if(i % 30 == 0) honap++; //megfelelo honap szam hozzarendelese a naphoz if(i % 30 == 0) honap++; //megfelelo honap szam hozzarendelese a naphoz
@@ -34,13 +73,30 @@ namespace Homerseklet_elemzes {
napok[i] = new Nap(evszak, honap); napok[i] = new Nap(evszak, honap);
} }
Console.Write("Kérem a nap számát az évben "); while(folytatas == "igen") {
short nap_szam = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("Mit szeretne tudni?");
Console.WriteLine(); Console.WriteLine("Egy nap adatai (1) | Egy honap adatai (2) | Egy evszak adatai (3) | Az ev adati (4)");
napi_adat(napok, nap_szam); short kerdes = Convert.ToInt16(Console.ReadLine());
if (kerdes == 1) {
Console.WriteLine("Adja meg a nap számát");
short nap = Convert.ToInt16(Console.ReadLine());
napi_adat(napok, nap);
} else if (kerdes == 2) {
Console.WriteLine("Adja meg a hónap számát ");
honap = Convert.ToInt16(Console.ReadLine());
Console.WriteLine(havi_adat(napok, honap));
} else if (kerdes == 3) {
Console.WriteLine("Adja meg az evszak számát ");
evszak = Convert.ToInt16(Console.ReadLine());
Console.WriteLine(evszak_adat(napok, evszak));
}else if(kerdes == 4) {
Console.WriteLine(eves_adat(napok));
}
Console.ReadKey(); Console.WriteLine("Szeretne még kérdezni? (igen/nem)");
folytatas = Console.ReadLine();
}
} }
} }
} }

View File

@@ -6,3 +6,11 @@ C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.Sugge
C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.CoreCompileInputs.cache C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.CoreCompileInputs.cache
C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.exe C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.exe
C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.pdb C:\dev\c#\c-sharp\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.pdb
C:\dev\c#\Homerseklet_elemzes\bin\Debug\Homerseklet_elemzes.exe.config
C:\dev\c#\Homerseklet_elemzes\bin\Debug\Homerseklet_elemzes.exe
C:\dev\c#\Homerseklet_elemzes\bin\Debug\Homerseklet_elemzes.pdb
C:\dev\c#\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.AssemblyReference.cache
C:\dev\c#\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.SuggestedBindingRedirects.cache
C:\dev\c#\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.csproj.CoreCompileInputs.cache
C:\dev\c#\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.exe
C:\dev\c#\Homerseklet_elemzes\obj\Debug\Homerseklet_elemzes.pdb

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace RegularExpressions {
internal class Program {
static void Main(string[] args) {
/*Hivatalos dokumentáció a Regexről
*https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
*https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
*https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=net-6.0
*/
Regex regex = new Regex("^[1-9][0-9]*");
//a ^ karakter mondja meg hogy a strng elejétől kezdje
//a keretes zárójelen belül egy karakter sorozatot adunk meg, ezek között keresi a találatot (ennek a tagadása [^1-9])
//az első karakter sorozatot az első karakterrel vizsgálja a stringből
//a következö karaktersorozat pedig az utánna lévő karaktereket vizsgája
//a * nulla vagy több előfordulást jelent ebben az esetben a második karaktersorozatot nézi az első utáni összes karakterre
//a $ jel jelöli a string végét
string s1 = "012345";
string s2 = "112345";
string s3 = "2";
Console.WriteLine("{0} {1}",s1,(regex.IsMatch(s1) ? "természetes szám" : "nem természetes szám"));
Console.WriteLine("{0} {1}",s2,(regex.IsMatch(s2) ? "természetes szám" : "nem természetes szám"));
Console.WriteLine("{0} {1}",s3,(regex.IsMatch(s3) ? "természetes szám" : "nem természetes szám"));
////////////////////////////////////////////////////////////////////////////////////////////////////
string s = @"^(\+)[1-9][0-9]{1,2}\s[1-9][0-9]{1,2}\s(\d{3}(-)){2}\d{3}$";
Regex pattern = new Regex(s);
//a @ azt jelöli hogy a string tartalmaz speciális karaktereket
//a + jel elé egy \ kell írni mivel speciális karakter és a Regex is használja
//a {1,2} az jelöli hogy a plusz jel után minimun egy de max két karakter állhat (az előtte lévő karaktersorozatra vonatkozik)
//a \s egy szóközt jelöl
//a \d számokat jelöl ez esetben (\d{3}) azt jelenti hogy 3 db szám jön egymás után pl: 123
//ez után következzen két db kötőjel és ez kétszer fordul elő
//majd a végén megismételjük a hármas számsorozatot csak a kötőjel nélkül
string ss1 = "+36 30 661-345-612";
string ss2 = "+3630 661-567-233";
string ss3 = "+56 30 667-876-987-456";
Console.WriteLine(pattern.IsMatch(ss1)); // true
Console.WriteLine(pattern.IsMatch(ss2)); // false
Console.WriteLine(pattern.IsMatch(ss3)); // false
///////////////////////////////////////////////////////////////////////////////////////////
//További felhasználási módok
//Egy string részének az átírása
string pattern2 = "(Mr\\.? |Mrs\\.? |Miss |Ms\\.? )";
string[] names = { "Mr. Henry Hunt", "Ms. Sara Samuels",
"Abraham Adams", "Ms. Nicole Norris" };
foreach (string name in names)
Console.WriteLine(Regex.Replace(name, pattern2, String.Empty));
// Henry Hunt
// Sara Samuels
// Abraham Adams
// Nicole Norris
//Duplikáció keresés
string pattern3 = @"\b(\w+?)\s\1\b";
string input = "This this is a nice day. What about this? This tastes good. I saw a a dog.";
foreach (Match match in Regex.Matches(input, pattern3, RegexOptions.IgnoreCase))
Console.WriteLine("{0} (duplicates '{1}') at position {2}",
match.Value, match.Groups[1].Value, match.Index);
Console.ReadKey();
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RegularExpressions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RegularExpressions")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b8063178-720e-430c-b364-dc3f1dfce42c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,53 @@
<?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>{B8063178-720E-430C-B364-DC3F1DFCE42C}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>RegularExpressions</RootNamespace>
<AssemblyName>RegularExpressions</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

View File

@@ -0,0 +1 @@
7f4b213b428f4c013f19137338418ee1f5525793

View File

@@ -0,0 +1,8 @@
C:\dev\c#\RegularExpressions\bin\Debug\RegularExpressions.exe.config
C:\dev\c#\RegularExpressions\bin\Debug\RegularExpressions.exe
C:\dev\c#\RegularExpressions\bin\Debug\RegularExpressions.pdb
C:\dev\c#\RegularExpressions\obj\Debug\RegularExpressions.csproj.AssemblyReference.cache
C:\dev\c#\RegularExpressions\obj\Debug\RegularExpressions.csproj.SuggestedBindingRedirects.cache
C:\dev\c#\RegularExpressions\obj\Debug\RegularExpressions.csproj.CoreCompileInputs.cache
C:\dev\c#\RegularExpressions\obj\Debug\RegularExpressions.exe
C:\dev\c#\RegularExpressions\obj\Debug\RegularExpressions.pdb

Binary file not shown.

Binary file not shown.

View File

@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuborekRendezes", "BuborekR
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RekurzivFaktorialis", "RekurzivFaktorialis\RekurzivFaktorialis.csproj", "{F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RekurzivFaktorialis", "RekurzivFaktorialis\RekurzivFaktorialis.csproj", "{F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegularExpressions", "RegularExpressions\RegularExpressions.csproj", "{B8063178-720E-430C-B364-DC3F1DFCE42C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RekurzivHatvany", "RekurzivHatvany\RekurzivHatvany.csproj", "{DA385DD5-70CE-4750-BDF8-03915D70F5B9}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RekurzivHatvany", "RekurzivHatvany\RekurzivHatvany.csproj", "{DA385DD5-70CE-4750-BDF8-03915D70F5B9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kor", "Kor\Kor.csproj", "{70C74504-C5C5-4992-A4FF-F00ADAAF7126}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kor", "Kor\Kor.csproj", "{70C74504-C5C5-4992-A4FF-F00ADAAF7126}"
@@ -57,6 +59,10 @@ Global
{F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Release|Any CPU.Build.0 = Release|Any CPU {F7BEEB1C-EB73-42E8-A148-3DB8C96B8D56}.Release|Any CPU.Build.0 = Release|Any CPU
{B8063178-720E-430C-B364-DC3F1DFCE42C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8063178-720E-430C-B364-DC3F1DFCE42C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8063178-720E-430C-B364-DC3F1DFCE42C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8063178-720E-430C-B364-DC3F1DFCE42C}.Release|Any CPU.Build.0 = Release|Any CPU
{DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {DA385DD5-70CE-4750-BDF8-03915D70F5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU

Binary file not shown.

Binary file not shown.

View File

@@ -4,3 +4,11 @@ C:\dev\c#\c-sharp\c-sharp\bin\Debug\c-sharp.pdb
C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.csproj.CoreCompileInputs.cache C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.csproj.CoreCompileInputs.cache
C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.exe C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.exe
C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.pdb C:\dev\c#\c-sharp\c-sharp\obj\Debug\c-sharp.pdb
C:\dev\c#\c-sharp\bin\Debug\c-sharp.exe.config
C:\dev\c#\c-sharp\bin\Debug\c-sharp.exe
C:\dev\c#\c-sharp\bin\Debug\c-sharp.pdb
C:\dev\c#\c-sharp\obj\Debug\c-sharp.csproj.AssemblyReference.cache
C:\dev\c#\c-sharp\obj\Debug\c-sharp.csproj.SuggestedBindingRedirects.cache
C:\dev\c#\c-sharp\obj\Debug\c-sharp.csproj.CoreCompileInputs.cache
C:\dev\c#\c-sharp\obj\Debug\c-sharp.exe
C:\dev\c#\c-sharp\obj\Debug\c-sharp.pdb

Binary file not shown.

Binary file not shown.