init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
Kreta.BusinessLogic/Classes
78
Kreta.BusinessLogic/Classes/SubstringExtension.cs
Normal file
78
Kreta.BusinessLogic/Classes/SubstringExtension.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
namespace Kreta.BusinessLogic.Classes
|
||||
{
|
||||
public static class SubstringExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Sortörés kezelése
|
||||
/// </summary>
|
||||
public enum StringWrapMode
|
||||
{
|
||||
Cut = 0,
|
||||
Wrap = 1,
|
||||
TruncateTail = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abban az esetben, ha a startindex nagyobb mint 0, levágja a szöveg elejét
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="startindex"></param>
|
||||
/// <param name="wrapping"></param>
|
||||
/// <returns></returns>
|
||||
public static string Wrap(this string text, int startindex, StringWrapMode wrapping = StringWrapMode.Cut)
|
||||
{
|
||||
return Wrap(text, startindex, text.Length, wrapping);
|
||||
}
|
||||
|
||||
public static string Wrap(this string text, int startindex, int maxlength, StringWrapMode wrapping = StringWrapMode.Cut)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (startindex < 0 || (startindex == 0 && maxlength == text.Length))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
int maxIndex = text.Length - 1;
|
||||
int lastIndex = startindex + maxlength;
|
||||
|
||||
if (lastIndex > maxIndex)
|
||||
{
|
||||
return text.Substring(startindex, maxIndex - startindex);
|
||||
}
|
||||
|
||||
switch (wrapping)
|
||||
{
|
||||
case StringWrapMode.TruncateTail:
|
||||
return string.Format("{0}...", text.Substring(startindex, maxlength - 3));
|
||||
case StringWrapMode.Wrap:
|
||||
int lastSpaceBeforeCut = -1;
|
||||
int lastSpaceAfterCut = -1;
|
||||
for (int i = 0; i < maxIndex; i++)
|
||||
{
|
||||
if (text[i] == ' ')
|
||||
{
|
||||
if (i > maxlength)
|
||||
{
|
||||
lastSpaceAfterCut = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastSpaceBeforeCut = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastSpaceBeforeCut == -1 || lastSpaceAfterCut == -1
|
||||
? string.Format("{0}...", text.Substring(startindex, maxlength - 3))
|
||||
: text.Substring(startindex, lastSpaceBeforeCut);
|
||||
|
||||
default:
|
||||
return text.Substring(startindex, maxlength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue