📄 stringtools.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace DSProcessing
{
/// <summary>
/// String tools class, a part of DSProcessing library.
/// author: Jan Sova
/// mailto: twardowski@email.cz
///
/// -------------------------------------------------------------------------
///
/// DSProcessing - C#/C++ library of signal processing, speech processing,
/// and communications classes and functions
///
/// Copyright (C) 2007-2008
///
/// This program is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with this program; if not, write to the Free Software
/// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
///
///-------------------------------------------------------------------------
/// </summary>
public class StringTools
{
/// <summary>
/// Retirn time formated in string.
/// </summary>
/// <param name="num">Number of secunds</param>
/// <returns></returns>
public static string getTime(int num)
{
int minuty = (int)(num / 60);
int sekundy = num % 60;
string returnValue = "";
if (minuty < 10)
{
if (sekundy < 10)
{
returnValue = "0" + minuty.ToString() + ":" + "0" + sekundy.ToString();
}
else
{
returnValue = "0" + minuty.ToString() + ":" + sekundy.ToString();
}
}
else
{
if (sekundy < 10)
{
returnValue = minuty.ToString() + ":" + "0" + sekundy.ToString();
}
else
{
returnValue = minuty.ToString() + ":" + sekundy.ToString();
}
}
return returnValue;
}
/// <summary>
/// Usefull string formate.
/// </summary>
/// <param name="doubleText">Double value (going to be processed)</param>
/// <param name="textp"></param>
public static void NumberFormate(double doubleText, ref string textp)
{
if (doubleText == (int)doubleText)
{
textp = doubleText.ToString("0");
}
else
{
if (doubleText == 0)
textp = doubleText.ToString("0.00");
else if (doubleText < 0.001 && doubleText > -0.001)
textp = doubleText.ToString("0.00e+0");
else if (doubleText < 10 && doubleText > -10)
textp = doubleText.ToString("0.000");
else if (doubleText < 100 && doubleText > -100)
textp = doubleText.ToString("00.00");
else if (doubleText > 1000 || doubleText < -1000)
textp = doubleText.ToString("000e+0");
else
textp = doubleText.ToString("000.00");
}
}
/// <summary>
/// Usefull string formate.
/// </summary>
/// <param name="doubleText"></param>
/// <returns></returns>
public static string getNumberFormate(double doubleText)
{
string returnValue = "";
if (doubleText == (int)doubleText)
{
returnValue = doubleText.ToString("0");
}
else
{
if (doubleText == 0)
returnValue = doubleText.ToString("0.00");
else if (doubleText < 0.001 && doubleText > -0.001)
returnValue = doubleText.ToString("0.00e+0");
else if (doubleText < 10 && doubleText > -10)
returnValue = doubleText.ToString("0.000");
else if (doubleText < 100 && doubleText > -100)
returnValue = doubleText.ToString("00.00");
else if (doubleText > 1000 || doubleText < -1000)
returnValue = doubleText.ToString("000.0");
else if (doubleText > 10000 || doubleText < -10000)
returnValue = doubleText.ToString("0000e+0");
else
returnValue = doubleText.ToString("000.00");
}
return returnValue;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -