• [No000089]String的(补空位)左对齐,(补空位)右对齐


    using System;
    
    namespace Chinese中文排序Sort
    {
        internal class Program
        {
            /// <summary>
            /// 取子字符串
            /// </summary>
            /// <param name="oriStr">原字符串</param>
            /// <param name="beginIndex">取子串的起始位置</param>
            /// <param name="len">取子串的长度</param>
            /// <returns>子字符串</returns>
            public static String subString(String oriStr, int beginIndex, int len)
            {
                int strlen = oriStr.Length;
                beginIndex = beginIndex - 1;
                string str = null;
                if (strlen <= beginIndex)
                {
                    Console.WriteLine("out of " + oriStr + "'s length, please recheck!");
                }
                else if (strlen <= beginIndex + len)
                {
                    str = oriStr.Substring(beginIndex);
                }
                else {
                    str = oriStr.Substring(beginIndex, beginIndex + len);
                }
                return str;
            }
    
            /// <summary>
            /// 左补位,右对齐
            /// </summary>
            /// <param name="oriStr">原字符串</param>
            /// <param name="len">目标字符串长度</param>
            /// <param name="alexin">补位字符</param>
            /// <returns>目标字符串</returns>
            public static String padRight(String oriStr, int len, char alexin)
            {
                int strlen = oriStr.Length;
                string str = null;
                if (strlen < len)
                {
                    for (int i = 0; i < len - strlen; i++)
                    {
                        str = str + alexin;
                    }
                }
                str = str + oriStr;
                return str;
            }
    
            /// <summary>
            /// 右补位,左对齐
            /// </summary>
            /// <param name="oriStr">原字符串</param>
            /// <param name="len">目标字符串长度</param>
            /// <param name="alexin">补位字符</param>
            /// <returns>目标字符串</returns>
            public static String padLeft(String oriStr, int len, char alexin)
            {
                int strlen = oriStr.Length;
                string str = null;
                if (strlen < len)
                {
                    for (int i = 0; i < len - strlen; i++)
                    {
                        str = str + alexin;
                    }
                }
                str = oriStr + str;
                return str;
            }
    
            private static void Main(string[] args)
            {
                string sTemp = "0123456789";
                Console.WriteLine(sTemp.Substring(0, 3));//012
                UInt64 uintROWNUM = 0;
                UInt64 sInt = ++uintROWNUM;
                Console.WriteLine(sInt.ToString());//1
    
    
    
    
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    Python3标准库:copy复制对象
    Python3标准库:weakref对象的非永久引用
    Python3标准库:queue线程安全的FIFO实现
    Python3标准库:bisect维护有序列表
    Python3标准库:struct二进制数据结构
    Python3标准库:heapq堆排序算法
    Python3标准库:array数组
    Python3标准库:collections容器数据类型
    20-如何运行容器?
    19-Docker 镜像小结
  • 原文地址:https://www.cnblogs.com/Chary/p/No000089.html
Copyright © 2020-2023  润新知