1 Star 0 Fork 122

库卡青年/DevelopAssistant

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TsqlFormat.cs 2.35 KB
一键复制 编辑 原始数据 按行查看 历史
wxd_tony1984 提交于 2019-05-01 00:54 +08:00 . 一些修改
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using TSqlFormatter;
using TSqlFormatter.Formatters;
namespace DevelopAssistant.Format
{
public class TsqlFormatHelper
{
public static string FormatToTSQL(string strsql, bool caseWrite)
{
string result = string.Empty;
if (string.IsNullOrEmpty(strsql))
return strsql;
try
{
//bool errorsEncountered = false;
//result = SqlFormattingManager.DefaultFormat(strsql, ref errorsEncountered);
bool errorsEncountered = false;
SqlFormattingManager formaterManager = new SqlFormattingManager();
TSqlStandardFormatter formater = (TSqlStandardFormatter)formaterManager.Formatter;
formater.Options.UppercaseKeywords = caseWrite;
result = formaterManager.Format(strsql, ref errorsEncountered);
}
catch (Exception ex)
{
result = strsql;
}
return result;
}
public static string FormatToString(string strsql,bool caseWrite)
{
return FormatToTSQL(strsql, caseWrite);
}
public static string CompressToString(string strsql)
{
string result = string.Empty;
strsql = strsql.Replace("//", "");
strsql = strsql.Replace('\r', ' ');
strsql = strsql.Replace('\n', ' ');
//strsql = Regex.Replace(strsql, " +", " ", RegexOptions.None);
char[] char_array = strsql.ToCharArray();
List<char> char_list = new List<char>();
int space_count = 0;
for (int i = 0, len = char_array.Length; i < len; i++)
{
char chr = char_array[i];
if (chr == ' ')
{
space_count++;
if (space_count == 1)
{
char_list.Add(chr);
}
}
if (chr != ' ')
{
space_count = 0;
char_list.Add(chr);
}
}
result =string.Concat(char_list.ToArray());
return result;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wwwpythonpw/DevelopAssistant.git
git@gitee.com:wwwpythonpw/DevelopAssistant.git
wwwpythonpw
DevelopAssistant
DevelopAssistant
master

搜索帮助