예제 #1
0
        /// <summary>
        /// SetValueToSprList
        /// </summary>
        /// <param name="str_list">"ValueName=Value"</param>
        /// <param name="param_name"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        public static string SetValueToSprList(string str_list, string param_name, string value, string separator)
        {
            int index_begin;

            param_name += "=";

            int param_name_Length = param_name.Length;

            if ((index_begin = FastString.IndexOf(str_list, separator + param_name)) >= 0 ||
                (index_begin = FastString.IndexOf(str_list, param_name)) == 0)
            {
                int index_end;
                if (index_begin == 0)
                {
                    index_begin += param_name_Length;
                }
                else
                {
                    index_begin += separator.Length + param_name_Length;
                }

                index_end = FastString.IndexOf(str_list, separator, index_begin);
                if (index_end > 0)
                {
                    //str_list=str_list.Substring(index_begin,index_end-index_begin);
                    str_list = str_list.Remove(index_begin, index_end - index_begin);
                    str_list = str_list.Insert(index_begin, value);

                    return(str_list);
                }
                else
                {
                    //return str_list.Substring(index_begin);
                    str_list = str_list.Remove(index_begin, str_list.Length - index_begin);
                    str_list = str_list.Insert(index_begin, value);

                    return(str_list);
                }
            }
            if (str_list.Length > 0)
            {
                if (str_list[str_list.Length - 1].ToString() != separator)
                {
                    str_list += separator.ToString();
                }
            }

            str_list = str_list + param_name + value + separator;

            return(str_list);
        }
예제 #2
0
        /// <summary>
        /// GetValueFromSprList
        /// </summary>
        /// <param name="str_list">"ValueName=Value"</param>
        /// <param name="param_name"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        public static string GetValueFromSprList(string str_list, string param_name, char separator)
        {
            if (FastString.IsEmpty(str_list) || FastString.IsEmpty(param_name))
            {
                return("");
            }

            int index_begin;

            param_name += "=";

            int param_name_Length = param_name.Length;

            if ((index_begin = FastString.IndexOf(str_list, separator + param_name)) >= 0 ||
                (index_begin = FastString.IndexOf(str_list, param_name)) == 0)
            {
                if (index_begin == 0)
                {
                    index_begin += param_name_Length;
                }
                else
                {
                    index_begin += 1 + param_name_Length;
                }

                int index_end;

                index_end = str_list.IndexOf(separator, index_begin);
                if (index_end > 0)
                {
                    return(str_list.Substring(index_begin, index_end - index_begin));
                }
                else
                {
                    return(str_list.Substring(index_begin));
                }
            }
            return("");
        }
예제 #3
0
        //



        #region ReplaceIfSeparated(string str_in, char c_from, char c_to)
        /// <summary>
        /// StrReplace
        /// </summary>
        /// <param name="str_in"></param>
        /// <param name="c"></param>
        /// <param name="beg"></param>
        /// <param name="len"></param>
        public static string ReplaceIfSeparated(string str_in, string str_old, string str_new, string sep_chars)
        {
            if (str_in == null || str_in.Length == 0 || str_old == null || str_old.Length == 0)
            {
                return(str_in);
            }

            if (str_new == null)
            {
                str_new = "";
            }

            int index  = 0;
            int index1 = 0;

            while (index >= 0)
            {
                index1 = FastString.IndexOf(str_in, str_old, index);
                if (index1 < 0)
                {
                    break;
                }
                index = index1 + 1;

                if (index1 > 0)
                {
                    if (sep_chars != null)
                    {
                        bool fl = false;
                        for (int i = 0; i < sep_chars.Length; i++)
                        {
                            if (str_in[index1 - 1] == sep_chars[i])
                            {
                                fl = true;
                                break;
                            }
                        }
                        if (fl == false)
                        {
                            continue;
                        }
                    }
                }
                if (index1 + str_old.Length != str_in.Length)
                {
                    if (sep_chars != null)
                    {
                        bool fl = false;
                        for (int i = 0; i < sep_chars.Length; i++)
                        {
                            if (str_in[index1 + str_old.Length] == sep_chars[i])
                            {
                                fl = true;
                                break;
                            }
                        }
                        if (fl == false)
                        {
                            continue;
                        }
                    }
                }
                str_in = str_in.Remove(index1, str_old.Length);
                str_in = str_in.Insert(index1, str_new);
            }
            return(str_in);
        }