Exemple #1
0
        /// <summary>省略の文字列を取得</summary>
        /// <param name="input">入力文字列</param>
        /// <param name="maxByteLen">最大のバイト数</param>
        /// <returns></returns>
        public static String GetOmitString(String input, int maxByteLen)
        {
            // 変換対象文字列のバイト数を求める

            int inputByteLength = CheckUtil.Get_ByteLength(input);

            // 変換対象のバイト数が、保持するバイト数以内に
            // 収まっている場合は、そのままの文字列を返す
            if (inputByteLength <= maxByteLen)
            {
                return(input);
            }
            // 保持バイト長
            int keepByteLength = maxByteLen - 3;

            // バイト変換した文字列の桁数が、指定バイト数を上回る箇所を判定

            for (int i = 0; i <= input.Length; i++)
            {
                int checkStrByteLength = CheckUtil.Get_ByteLength(input.Substring(0, i));

                if (keepByteLength < checkStrByteLength)
                {
                    // 変換文字のバイト数が指定バイト数を上回る位置に来たら、
                    // その手前までの文字列(+略号)を返す
                    return(input.Substring(0, i - 1) + SystemConst.SUFFIX_JOB);
                }
            }
            return(input);
        }