コード例 #1
0
ファイル: StringUtils.cs プロジェクト: Harver/cms-1
        private static string ParseReplace(string parsedContent, string replace, string to)
        {
            if (replace.IndexOf(',') != -1)
            {
                var replaceList = TranslateUtils.StringCollectionToStringList(replace);
                var toList      = TranslateUtils.StringCollectionToStringList(to);

                if (replaceList.Count == toList.Count)
                {
                    for (var i = 0; i < replaceList.Count; i++)
                    {
                        parsedContent = parsedContent.Replace(replaceList[i], toList[i]);
                    }

                    return(parsedContent);
                }
            }

            string retval;

            if (replace.StartsWith("/") && replace.EndsWith("/"))
            {
                retval = RegexUtils.Replace(replace.Trim('/'), parsedContent, to);
            }
            else
            {
                retval = parsedContent.Replace(replace, to);
            }

            return(retval);
        }
コード例 #2
0
        public static bool Contains(string strCollection, string item)
        {
            var contains = false;

            if (!string.IsNullOrEmpty(strCollection) && !string.IsNullOrEmpty(item))
            {
                var list = TranslateUtils.StringCollectionToStringList(strCollection);
                contains = list.Contains(item.Trim());
            }
            return(contains);
        }
コード例 #3
0
        public static void Import(string filePath, out List <string> head, out List <List <string> > rows)
        {
            head = new List <string>();
            rows = new List <List <string> >();

            var valueList = new List <string>();

            //string content = FileUtils.ReadText(filePath, ECharset.utf_8);
            var content = FileUtils.ReadText(filePath, ECharset.gb2312);

            if (!string.IsNullOrEmpty(content))
            {
                valueList = TranslateUtils.StringCollectionToStringList(content, '\n');
            }

            if (valueList.Count > 1)
            {
                head      = TranslateUtils.StringCollectionToStringList(valueList[0]);
                valueList = valueList.GetRange(1, valueList.Count - 1);
            }

            foreach (var str in valueList)
            {
                var row = new List <string>();

                var value = str.Replace(@"""""", @"""");
                var list  = TranslateUtils.StringCollectionToStringList(value);

                if (list.Count != head.Count)
                {
                    continue;
                }
                foreach (var r in list)
                {
                    row.Add(r.Trim('"'));
                }
                rows.Add(row);
            }
        }
コード例 #4
0
        public static string ToInTopSqlString(string tableName, string columns, string whereString, string orderString, int topN)
        {
            var builder = new StringBuilder();

            if (WebConfigUtils.DatabaseType != DatabaseType.Oracle)
            {
                foreach (var column in TranslateUtils.StringCollectionToStringList(columns))
                {
                    builder.Append($"T.{column}, ");
                }
                builder.Length = builder.Length - 2;
                return
                    ($"SELECT {builder} FROM ({ToTopSqlString(tableName, columns, whereString, orderString, topN)}) AS T");
            }

            foreach (var column in TranslateUtils.StringCollectionToStringList(columns))
            {
                builder.Append($"{column}, ");
            }
            builder.Length = builder.Length - 2;
            return
                ($"SELECT {builder} FROM ({ToTopSqlString(tableName, columns, whereString, orderString, topN)})");
        }