Exemple #1
0
    public void In(
        [FriendlyName("Target", "The string variable to be split into new sub-strings.")] string Target,
        [FriendlyName("Separator", "The character to use to split the string into sub-strings."), SocketState(false, false)] string Separator,
        [FriendlyName("Split Options", "Determine if empty sub-strings should be added to the String List."), SocketState(false, false)] System.StringSplitOptions SplitOptions,
        [FriendlyName("Result (List)", "The String List containing the sub-strings.")] out string[] Result,
        [FriendlyName("Count", "The number of sub-strings created from the split."), SocketState(false, false)] out int Count
        )
    {
        string[] tmpResult;

        // Determine what to split
        if (Separator != "" && Target.Contains(Separator))
        {
            char[] delimiter = Separator.ToCharArray();
            tmpResult = Target.Split(delimiter, SplitOptions);
        }
        else
        {
            tmpResult = new string[1] {
                Target
            };
        }

        Result = tmpResult;
        Count  = tmpResult.Length;
    }
Exemple #2
0
    // csvの読み込み
    public void ReadCSV(string path, ref string[,] _data)
    {
        StreamReader streamReader = new StreamReader(Application.dataPath + path);
        string       strStream    = streamReader.ReadToEnd();

        Debug.Log(strStream);
        System.StringSplitOptions option = System.StringSplitOptions.None;

        string[] rows    = strStream.Split(new char[] { '\n' }, option);
        char[]   spliter = new char[1] {
            ','
        };
        int height = rows.Length;
        int width  = rows[0].Split(spliter, option).Length;

        Debug.Log(height);
        Debug.Log(width);

        _data = new string[height, width];
        for (int i = 0; i < height; i++)
        {
            string[] stringRow = rows[i].Split(spliter, option);
            foreach (string tmp in stringRow)
            {
                Debug.Log(tmp);
            }
            for (int j = 0; j < width; j++)
            {
                _data[i, j] = stringRow[j];
            }
        }
    }
Exemple #3
0
    public int[,] readCSVData(string path, ref string [,] sData)
    {
        StreamReader sr = new StreamReader(path);

        string strstream = sr.ReadToEnd();

        System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

        string[] lines = strstream.Split(new char[] { '\r', '\n' }, option);

        char[] spliter = new char[1] {
            ','
        };

        int h = lines.Length;
        int w = lines[0].Split(spliter, option).Length;

        sData = new string[h, w];

        for (int i = 0; i < h; i++)
        {
            string[] splitedData = lines[i].Split(spliter, option);

            for (int j = 0; j < w; j++)
            {
                sData[i, j] = splitedData[j];
            }
        }
        convert2DArrayType(ref sData, ref stageMapData, h, w);

        return(stageMapData);
    }
    public static void Map_Load(string file_path, ref Map_Data map_data)
    {
        //StreamReader sr = new StreamReader(Application.dataPath + file_path);
        StreamReader sr         = new StreamReader(file_path);
        string       str_stream = sr.ReadToEnd();

        System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

        string[] lines   = str_stream.Split(new char[] { '\r', '\n' }, option);
        char[]   spliter = new char[1] {
            ','
        };

        map_data.Height   = lines.Length;
        map_data.Width    = lines[0].Split(spliter, option).Length;
        map_data.Map_data = new int[map_data.Height, map_data.Width];

        for (int i = 0; i < map_data.Height; i++)
        {
            for (int j = 0; j < map_data.Width; j++)
            {
                string[] read_str_data = lines[i].Split(spliter, option);

                map_data.Map_data[i, j] = int.Parse(read_str_data[j]);

                //  デバッグ表示用
                //Debug.Log(map_data.Map_data[i, j]);
            }
        }
    }
Exemple #5
0
    //mapデータの読み込み
    private void LoadFromAsset(TextAsset asset)
    {
        string txtMapData = asset.text;

        //splitメソッドで、からの要素を削除するためのオプション
        System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

        //一行ずつ取り出す
        string[] lines = txtMapData.Split(new char[] { '\r', '\n' }, option);

        //','区切りで1文字ずつとりだす
        char[] spliter = new char[1] {
            ','
        };

        string[] sizewh = lines[0].Split(spliter, option);
        stageData.width  = int.Parse(sizewh[0]);
        stageData.length = int.Parse(sizewh[1]);

        char[,] mapdata = new char[stageData.length, stageData.width];

        for (int lineCnt = 0; lineCnt < stageData.length; lineCnt++)
        {
            string[] data = lines[stageData.length - lineCnt].Split(spliter, option);

            for (int col = 0; col < stageData.width; col++)
            {
                mapdata[lineCnt, col] = data[col][0];
            }
        }
        stageData.data = mapdata;
    }
Exemple #6
0
    private void LoadFromAsset(TextAsset asset)
    {
        m_mapData.offset_x = MAP_ORIGIN_X;
        m_mapData.offset_z = MAP_ORIGIN_Z;

        if (asset != null)
        {
            string txtMapData = asset.text;

            // 빈 공간의 요소를 삭제하기 위한 옵션.
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

            // 개행 코드로 1행마다 구분한다.
            string[] lines = txtMapData.Split(new char[] { '\r', '\n' }, option);

            // "," 으로 1문자마다 구분한다.
            char[] spliter = new char[1] {
                ','
            };

            // 첫 행은 맵의 크기.
            string[] sizewh = lines[0].Split(spliter, option);
            m_mapData.width  = int.Parse(sizewh[0]);
            m_mapData.length = int.Parse(sizewh[1]);

            char[,]         mapdata = new char[m_mapData.length, m_mapData.width];

            for (int lineCnt = 0; lineCnt < m_mapData.length; lineCnt++)
            {
                // 텍스트 파일 중에서 큰 값이 설정되어도 상관없도록
                // 일단 점검하도록 한다.
                if (lines.Length <= lineCnt + 1)
                {
                    break;
                }

                // "," 으로 1문자마다 구분한다.
                string[] data = lines[m_mapData.length - lineCnt].Split(spliter, option);

                for (int col = 0; col < m_mapData.width; col++)
                {
                    if (data.Length <= col)
                    {
                        break;
                    }

                    mapdata[lineCnt, col] = data[col][0];
                }
            }
            m_mapData.data = mapdata;
        }
        else
        {
            Debug.LogWarning("Map data asset is null");
        }
    }
Exemple #7
0
    private void LoadFromAsset(TextAsset asset)
    {
        m_mapData.offset_x = MAP_ORIGIN_X;
        m_mapData.offset_z = MAP_ORIGIN_Z;

        if (asset != null)
        {
            string txtMapData = asset.text;

            // 将空元素删除的选项
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

            // 用换行符将每行切割开
            string[] lines = txtMapData.Split(new char[] { '\r', '\n' }, option);

            // 用“,”将每个字符分割开
            char[] spliter = new char[1] {
                ','
            };

            // 第一行地图的尺寸
            string[] sizewh = lines[0].Split(spliter, option);
            m_mapData.width  = int.Parse(sizewh[0]);
            m_mapData.length = int.Parse(sizewh[1]);

            char[,]         mapdata = new char[m_mapData.length, m_mapData.width];

            for (int lineCnt = 0; lineCnt < m_mapData.length; lineCnt++)
            {
                // 为了保证文本文件中即时指定了特别大的值也不会出问题
                // 进行检测
                if (lines.Length <= lineCnt + 1)
                {
                    break;
                }

                // 用“,”将每个字符分割开
                string[] data = lines[m_mapData.length - lineCnt].Split(spliter, option);

                for (int col = 0; col < m_mapData.width; col++)
                {
                    if (data.Length <= col)
                    {
                        break;
                    }

                    mapdata[lineCnt, col] = data[col][0];
                }
            }
            m_mapData.data = mapdata;
        }
        else
        {
            Debug.LogWarning("Map data asset is null");
        }
    }
Exemple #8
0
    private void LoadFromAsset(TextAsset asset)
    {
        m_mapData.offset_x = MAP_ORIGIN_X;
        m_mapData.offset_z = MAP_ORIGIN_Z;

        if (asset != null)
        {
            string txtMapData = asset.text;

            // 空の要素を削除するためのオプション.
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

            // 改行コードで1行ごとに切り出す.
            string[] lines = txtMapData.Split(new char[] { '\r', '\n' }, option);

            // "," で1文字ごとに切り出す.
            char[] spliter = new char[1] {
                ','
            };

            // 一行目はマップの大きさ.
            string[] sizewh = lines[0].Split(spliter, option);
            m_mapData.width  = int.Parse(sizewh[0]);
            m_mapData.length = int.Parse(sizewh[1]);

            char[,]         mapdata = new char[m_mapData.length, m_mapData.width];

            for (int lineCnt = 0; lineCnt < m_mapData.length; lineCnt++)
            {
                // テキストファイル中で大きすぎる値が指定されていても大丈夫なよう、
                // 一応チェックする.
                if (lines.Length <= lineCnt + 1)
                {
                    break;
                }

                // "," で1文字ごとに切り出す.
                string[] data = lines[m_mapData.length - lineCnt].Split(spliter, option);

                for (int col = 0; col < m_mapData.width; col++)
                {
                    if (data.Length <= col)
                    {
                        break;
                    }

                    mapdata[lineCnt, col] = data[col][0];
                }
            }
            m_mapData.data = mapdata;
        }
        else
        {
            Debug.LogWarning("Map data asset is null");
        }
    }
    // filePath : 拡張子はつけない
    public List <string[]> ReadCSV(string filePath)
    {
        // 行数を初期化
        totalRows = 0;
        // csvをロード
        TextAsset csv = Resources.Load(filePath) as TextAsset;
        // csvをテキストに変換
        StringReader reader = new StringReader(csv.text);
        // 格納するリストを用意
        List <string[]> data = new List <string[]>();

        while (reader.Peek() > -1)
        {
            // 1行を格納
            string line = reader.ReadLine();

            //// 空欄の場合は無視
            //System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;
            //// CR+LR の 改行 で区切る
            //string[] stringArray = line.Split(new char[] { '\r', '\n' }, option);

            // [,] で 区切る
            //string[] stringArray = line.Split(',');

            // [,] で 区切って 空欄の場合は無視
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;
            string[] stringArray             = line.Split(new char[] { ',' }, option);

            // 先頭が "//" なら追加しない
            if (stringArray[0] == "//")
            {
                continue;
            }

            data.Add(stringArray);
            ++totalRows;
        }

        if (totalRows == 0)
        {
            return(null);
        }
        totalRows = 0;
        return(data);
    }
Exemple #10
0
    // 读取地图数据
    void LoadMapData(TextAsset asset)
    {
        if (asset != null)
        {
            string txtMapData = asset.text;

            // 一个枚举类型,用于将分割后的字符数组中的空元素删除
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;

            // 以 \r \n 为分割符,并删除空元素
            string[] lines = txtMapData.Split(new char[] { '\r', '\n' }, option);
            string[] chars = lines[0].Split(new char[] { ',' }, option);

            mapData.length = chars.Length;
            mapData.width  = lines.Length;

            // 二维字符数组保存分割后的地图数据,数组的尺寸由地图尺寸决定
            char[,] mapPropData = new char[mapData.width, mapData.length];

            for (int row = 0; row < mapData.width; row++)
            {
                string[] tempData = lines[row].Split(new char[] { ',' }, option);

                for (int col = 0; col < mapData.length; col++)
                {
                    mapPropData[row, col] = tempData[col][0];
                }
            }

            mapData.data = mapPropData;

            UIManager.instance.tip.text  = "生成地图成功!";
            UIManager.instance.text.text = "当前地图索引:" + mapIndex;
        }
        else
        {
            Debug.LogWarning("地图文件为空");
            UIManager.instance.tip.text = "地图文件为空...";
        }
    }
Exemple #11
0
        private static string[] InternalSplit(java.lang.String str,
                                              object separator, int count,
                                              System.StringSplitOptions options)
        {
            if (count < 0)
            {
                throw new System.ArgumentOutOfRangeException();
            }

            bool omit = (options == System.StringSplitOptions.None) ? false
                      : (options == System.StringSplitOptions.RemoveEmptyEntries) ? true
                      : throw new System.ArgumentException();

            var emptyArray = new string[0];

            if (count == 0)
            {
                return(emptyArray);
            }

            int length = str.length();
            var list   = new java.util.ArrayList();

            if (separator is char[] charSeparator)
            {
                SplitCharacter(str, length, list, count, omit, charSeparator);
            }
            else if (separator is java.lang.String[] strSeparator)
            {
                SplitString(str, length, list, count, omit, strSeparator);
            }
            else // assuming separator is null
            {
                SplitWhiteSpace(str, length, list, count, omit);
            }

            return((string[])list.toArray(emptyArray));
        }
        // Float validator regex: http://regexstorm.net/tester
        // [\+\-]?\s*[0-9]*(?:\.[0-9]*)


        public static string[] SplitAndKeepSeparators(string value, System.StringSplitOptions splitOptions, params char[] separators)
        {
            System.Collections.Generic.List <string> splitValues =
                new System.Collections.Generic.List <string>();

            int itemStart = 0;

            for (int pos = 0; pos < value.Length; pos++)
            {
                for (int sepIndex = 0; sepIndex < separators.Length; sepIndex++)
                {
                    if (separators[sepIndex] == value[pos])
                    {
                        // add the section of string before the separator
                        // (unless its empty and we are discarding empty sections)
                        if (itemStart != pos || splitOptions == System.StringSplitOptions.None)
                        {
                            splitValues.Add(value.Substring(itemStart, pos - itemStart));
                        }
                        itemStart = pos + 1;

                        // add the separator
                        splitValues.Add(separators[sepIndex].ToString());
                        break;
                    }
                }
            }

            // add anything after the final separator
            // (unless its empty and we are discarding empty sections)
            if (itemStart != value.Length || splitOptions == System.StringSplitOptions.None)
            {
                splitValues.Add(value.Substring(itemStart, value.Length - itemStart));
            }

            return(splitValues.ToArray());
        }
    int EvaluateAtomicProposition(string Proposition)
    {
        System.StringSplitOptions options = System.StringSplitOptions.None;
        string[] Separator         = { "==" };
        string[] EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -1 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE EQUALITY SEPARATOR IN: " + Proposition);
                return(-1);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -2 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-2);
            }

            if (S1.Equals(S2))
            {
                return(1);
            }

            return(0);
        }

        Separator         = new string[] { "!=" };
        EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -3 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE INEQUALITY SEPARATOR IN: " + Proposition);
                return(-3);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -4 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-4);
            }

            if (S1.Equals(S2))
            {
                return(0);
            }

            return(1);
        }

        Separator         = new string[] { "<=" };
        EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -5 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE INEQUALITY SEPARATOR IN: " + Proposition);
                return(-5);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -6 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-6);
            }

            double D1 = 0;
            double D2 = 0;

            if (!double.TryParse(S1.ToString(), out D1) || !double.TryParse(S2.ToString(), out D2))
            {
                Debug.Log("ERROR -7 EVALUATING ATOMIC PROPOSITION. TERMS ARE NOT NUMBERS IN: " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-7);
            }

            if (D1 <= D2)
            {
                return(1);
            }
            return(0);
        }
        Separator         = new string[] { ">=" };
        EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -8 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE INEQUALITY SEPARATOR IN: " + Proposition);
                return(-8);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -9 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-9);
            }

            double D1 = 0;
            double D2 = 0;

            if (!double.TryParse(S1.ToString(), out D1) || !double.TryParse(S2.ToString(), out D2))
            {
                Debug.Log("ERROR -10 EVALUATING ATOMIC PROPOSITION. TERMS ARE NOT NUMBERS IN: " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-10);
            }

            if (D1 >= D2)
            {
                return(1);
            }
            return(0);
        }
        Separator         = new string[] { "<<" };
        EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -11 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE INEQUALITY SEPARATOR IN: " + Proposition);
                return(-11);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -12 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-12);
            }

            double D1 = 0;
            double D2 = 0;

            if (!double.TryParse(S1.ToString(), out D1) || !double.TryParse(S2.ToString(), out D2))
            {
                Debug.Log("ERROR -13 EVALUATING ATOMIC PROPOSITION. TERMS ARE NOT NUMBERS IN: " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-13);
            }

            if (D1 < D2)
            {
                return(1);
            }
            return(0);
        }
        Separator         = new string[] { ">>" };
        EqualitySeparator = Proposition.Split(Separator, options);
        if (EqualitySeparator.Length > 1) //if There are == separators.
        {
            if (EqualitySeparator.Length > 2)
            {
                Debug.Log("ERROR -14 EVALUATING ATOMIC PROPOSITION. MORE THAN ONE INEQUALITY SEPARATOR IN: " + Proposition);
                return(-14);
            }
            object S1 = EvaluateTerm(EqualitySeparator[0]);
            object S2 = EvaluateTerm(EqualitySeparator[1]);

            if (S1 == null || S2 == null)
            {
                Debug.Log("ERROR -15 EVALUATING TERMS " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-15);
            }

            double D1 = 0;
            double D2 = 0;

            if (!double.TryParse(S1.ToString(), out D1) || !double.TryParse(S2.ToString(), out D2))
            {
                Debug.Log("ERROR -16 EVALUATING ATOMIC PROPOSITION. TERMS ARE NOT NUMBERS IN: " + EqualitySeparator[0] + " OR " + EqualitySeparator[1]);
                return(-16);
            }

            if (D1 > D2)
            {
                return(1);
            }
            return(0);
        }

        Debug.Log("ERROR -17 EVALUATING ATOMIC PROPOSITION. SEPARATOR NOT IDENTIFIED IN: " + Proposition);
        return(-17);
    }
 public static System.Collections.Generic.IEnumerable <string> SplitLazy(this string value, System.StringSplitOptions options, params char[] separator)
 {
     return(value.SplitLazy(int.MaxValue, options, separator));
 }
        /// <summary>
        /// Splits a string into substrings that are based on the characters in an array.
        /// </summary>
        /// <param name="value">The string to split.</param>
        /// <param name="options"><see cref="StringSplitOptions.RemoveEmptyEntries"/> to omit empty array elements from the array returned; or <see cref="StringSplitOptions.None"/> to include empty array elements in the array returned.</param>
        /// <param name="count">The maximum number of substrings to return.</param>
        /// <param name="separator">A character array that delimits the substrings in this string, an empty array that contains no delimiters, or null. </param>
        /// <returns></returns>
        /// <remarks>
        /// Delimiter characters are not included in the elements of the returned array.
        /// If this instance does not contain any of the characters in separator the returned sequence consists of a single element that contains this instance.
        /// If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and return true if they are passed to the <see cref="Char.IsWhiteSpace"/> method.
        /// </remarks>
        public static System.Collections.Generic.IEnumerable <string> SplitLazy(this string value, int count = int.MaxValue, System.StringSplitOptions options = System.StringSplitOptions.None, params char[] separator)
        {
            if (count <= 0)
            {
                if (count < 0)
                {
                    throw new System.ArgumentOutOfRangeException(nameof(count), "Count cannot be less than zero.");
                }
                yield break;
            }

            if (string.IsNullOrEmpty(value) || count == 1 || value.IndexOfAny(separator).Equals(false))
            {
                yield return(value);

                yield break;
            }

            System.Func <char, bool> predicate;
            if (separator != null && separator.Length != 0)
            {
                predicate = (c) => Common.Extensions.Array.ArrayExtensions.Contains(separator, c);
            }
            else
            {
                predicate = char.IsWhiteSpace;
            }

            bool removeEmptyEntries = (options & System.StringSplitOptions.RemoveEmptyEntries) != 0;
            int  ct = 0;
            var  sb = new System.Text.StringBuilder();

            for (int i = 0; i < value.Length; ++i)
            {
                char c = value[i];
                if (false.Equals(predicate(c)))
                {
                    sb.Append(c);
                }
                else
                {
                    if (sb.Length != 0)
                    {
                        yield return(sb.ToString());

                        sb.Clear();
                    }
                    else
                    {
                        if (removeEmptyEntries)
                        {
                            continue;
                        }
                        yield return(string.Empty);
                    }

                    if (++ct >= count - 1)
                    {
                        if (removeEmptyEntries)
                        {
                            while (++i < value.Length && predicate(value[i]))
                            {
                                ;
                            }
                        }
                        else
                        {
                            ++i;
                        }
                        if (i < value.Length - 1)
                        {
                            sb.Append(value, i, value.Length - i);
                            yield return(sb.ToString());
                        }
                        yield break;
                    }
                }
            }

            if (sb.Length > 0)
            {
                yield return(sb.ToString());
            }
            else if (!removeEmptyEntries && predicate(value[value.Length - 1]))
            {
                yield return(string.Empty);
            }
        }
        public static string[] SplitTrimStart(this string ex, char[] seperator, int count, System.StringSplitOptions options)
        {
            if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator))
            {
                return(new string[Common.Binary.Zero]);
            }

            string[] results = ex.Split(seperator, count, options);

            for (int i = results.Length - 1; i >= Common.Binary.Zero; --i)
            {
                results[i] = results[i].TrimStart();
            }

            return(results);
        }
Exemple #17
0
        private static string[] GetCmdArgs(ref string cmd, out string first, out string[] subModuleArgs, System.StringSplitOptions options = System.StringSplitOptions.RemoveEmptyEntries)
        {
            cmd = cmd.Trim();

            var lines = cmd.Split(new string[] { System.Environment.NewLine }, options);

            if (lines.Length > 1)
            {
                cmd = lines[0];
            }

            first = cmd;
            var args = cmd.Split(new char[] { ' ' }, options);

            if (args.Length > 0)
            {
                first = args[0];
            }

            var subModuleArgsList    = new List <string>();
            var startsWithQuote      = false;
            var startsWithQuoteIndex = -1;

            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i].StartsWith(@"""") == true)
                {
                    startsWithQuoteIndex = i;
                    startsWithQuote      = true;
                }

                if (startsWithQuote == true)
                {
                    if (args[i].EndsWith(@"""") == true)
                    {
                        args[startsWithQuoteIndex] = args[startsWithQuoteIndex].Substring(1);
                        args[i] = args[i].Substring(0, args[i].Length - 1);

                        var str = string.Empty;
                        for (int j = startsWithQuoteIndex; j <= i; ++j)
                        {
                            str += args[j] + (j == i ? string.Empty : " ");
                        }
                        subModuleArgsList.Add(str);

                        startsWithQuote = false;
                    }
                    else if (startsWithQuoteIndex != i)
                    {
                        subModuleArgsList.Add(args[i]);
                    }
                }
                else
                {
                    args[i] = args[i].ToLower();
                    args[i] = Regex.Replace(args[i], @"\s+", " ");

                    subModuleArgsList.Add(args[i]);
                }
            }

            //subModuleArgs = string.Join(" ", args, 1, args.Length - 1).Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
            var argsOutput = subModuleArgsList.ToArray();

            //subModuleArgs = string.Join(" ", argsOutput, 1, argsOutput.Length - 1).Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

            if (subModuleArgsList.Count > 1)
            {
                subModuleArgs = new string[subModuleArgsList.Count - 1];
                for (int i = 1; i < subModuleArgsList.Count; ++i)
                {
                    subModuleArgs[i - 1] = subModuleArgsList[i];
                }
            }
            else
            {
                subModuleArgs = new string[0];
            }

            return(argsOutput);
        }
 public static string[] UnpackStringArray(string str, System.StringSplitOptions StringSplitOptions = System.StringSplitOptions.RemoveEmptyEntries)
 {
     return(str.Split(new string[] { StringArrayConcatenor }, StringSplitOptions));
 }
Exemple #19
0
 public static string[] Split(this string s, System.StringSplitOptions options, params string[] delimiter)
 {
     return(s.Split(delimiter, options));
 }
Exemple #20
0
 public static string[] Split(string str, System.StringSplitOptions option, params char[] separator)
 {
     return(str.Split(separator, option));
 }
Exemple #21
0
 public static string[] Split(string str, string[] separator, System.StringSplitOptions options)
 => InternalSplit((java.lang.String)(object) str, separator, System.Int32.MaxValue, options);
/// <summary>通过读取文件里的字符串转换成对应的地格生成地图
///
/// </summary>
        private void ReadMap()
        {
            System.StringSplitOptions option = System.StringSplitOptions.RemoveEmptyEntries;
            string[] lines = textAsset.text.Split(new char[] { '\r', '\n' }, option);
            for (int i = 0; i < lines.Length; i++)
            {
                string[] element = lines[i].Split(',');
                for (int j = 0; j < element.Length; j++)
                {
                    if (element[j] != "null")//如果字符串不为null,则生成地格挂载脚本。
                    {
                        string[]   upper   = element[j].Split(new char[] { ':' }, option);
                        GameObject mapunit = new GameObject("test" + i.ToString() + j.ToString());
                        mapunit.transform.parent = GameObject.Find("Map").transform;
                        mapunit.AddComponent <Button>();
                        switch (upper[0])
                        {
                        case "plane":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = planesplite;
                            break;

                        case "mountain":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = mountainsprite;
                            break;

                        case "deadtree":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = deadtreesprite;
                            break;

                        case "marsh":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = marshsprite;
                            break;

                        case "bush":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = bushsprite;
                            break;

                        case "desert":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = desertsprite;
                            break;

                        case "greenery":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = greenerysprite;
                            break;

                        case "oasis":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = oasissprite;
                            break;

                        case "grassland":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = grasslandsprite;
                            break;

                        case "wasteland":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = wastelandsprite;
                            break;

                        case "bloodstone":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = bloodstonesprite;
                            break;

                        case "cursestone":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = cursestonesprite;
                            break;

                        case "bonepit":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = bonepitsprite;
                            break;

                        case "obsidian":
                            mapunit.AddComponent <Plane>();
                            mapunit.transform.position = mapunit.GetComponent <Plane>().hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = obsidiansprite;
                            break;

                        //这里用的是默认的地格素材,
                        case "post":
                            MapUnit post = mapunit.AddComponent <Library>();
                            mapunit.transform.position = post.hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = test;
                            break;

                        case "key":
                            MapUnit key = mapunit.AddComponent <Key>();
                            mapunit.transform.position = key.hexVector.ChangeToNormalVect(new Vector3(i, j, 0));
                            mapunit.AddComponent <SpriteRenderer>();
                            mapunit.GetComponent <SpriteRenderer>().sprite = test;
                            break;

                        default:
                            Debug.Log("你文件写错了,回去看看");
                            break;
                        }

                        MeshCollider collider = mapunit.AddComponent <MeshCollider>();
                        collider.sharedMesh          = mesh;
                        mapunit.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

                        //如果有地格上层元素,传给MapElementManager处理
                        if (upper.Length == 2)
                        {
                            MapElementManager.Instance().InstalizeElement(upper[1], mapunit);
                        }
                        else
                        {
                        }
                    }
                }
            }
        }
Exemple #23
0
    /// <summary>
    /// ゴーストデータの読み込み
    /// </summary>
    void LoadGhost()
    {
        FileInfo     fi = new FileInfo(FilePathName);
        StreamReader sw = new StreamReader(fi.OpenRead());

        //SplitのOptionの設定
        System.StringSplitOptions SplitOption = System.StringSplitOptions.RemoveEmptyEntries;

        //ファイルデータをEOFまでストリングに読み込む
        string FileData = sw.ReadToEnd();

        //,区切りでStringデータを保存する
        string[] StringData = FileData.Split(new char[] { ',' }, SplitOption);

        //データを保存するリスト
        List <GhostCar.ReplayData> PlayerDataList = new List <GhostCar.ReplayData>();
        List <GhostCar.ReplayData> UFODataList    = new List <GhostCar.ReplayData>();

        //データのカウンター
        int nDataCount = 0;

        //Playerデータの読み込み
        for (; nDataCount < StringData.Length; ++nDataCount)
        {
            if (StringData[nDataCount] == PlayerDataName)
            {
                continue;
            }
            if (StringData[nDataCount] == UFODataName)
            {
                ++nDataCount; break;
            }
            GhostCar.ReplayData LoadData = new GhostCar.ReplayData();
            LoadData.fTime      = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.x = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.y = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.z = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.x   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.y   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.z   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.w   = float.Parse(StringData[nDataCount]);
            PlayerDataList.Add(LoadData);
        }
        //UFOデータの読み込み
        for (; nDataCount < StringData.Length; ++nDataCount)
        {
            GhostCar.ReplayData LoadData = new GhostCar.ReplayData();
            LoadData.fTime      = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.x = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.y = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Position.z = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.x   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.y   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.z   = float.Parse(StringData[nDataCount]); nDataCount++;
            LoadData.Rotate.w   = float.Parse(StringData[nDataCount]);
            UFODataList.Add(LoadData);
        }

        sw.Close();

        //データを受け渡す
        GhostObject.replayData    = PlayerDataList;
        GhostUFOObject.replayData = UFODataList;
    }
Exemple #24
0
 public static string[] Split(string str, string[] separator, int count, System.StringSplitOptions options)
 => InternalSplit((java.lang.String)(object) str, separator, count, options);