获取父页面URL的参数对应值及左对齐字符串

 1 ExpandedBlockStart.gif ContractedBlock.gif         /**/ /// <summary>
 2InBlock.gif       /// 返回包含中文字符的字符串长度。
 3InBlock.gif        /// C# 的string.Length中中文字只做1位统计,所以要将其转换为2位
 4InBlock.gif        /// </summary>       
 5InBlock.gif        /// <param name="strSource">要统计长度的字符串变量</param>
 6ExpandedBlockEnd.gif        /// <returns>字符串长度</returns>

 7 None.gif          public   static   int  GetLength( string  strSource)
 8 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 9InBlock.gif            return Encoding.GetEncoding("GB2312").GetBytes(strSource).Length;
10ExpandedBlockEnd.gif        }
 
11 ExpandedBlockStart.gifContractedBlock.gif         /**/ /// <summary>
12InBlock.gif        /// 左对齐字符串
13InBlock.gif         /// <remarks>
14InBlock.gif        /// 如原始字符串不满足参数<paramref name="length"/>指定的长度则在<paramref name="objectString"/>指定的原始字符串后补'~'
15InBlock.gif        /// </remarks>
16InBlock.gif        /// </summary>
17InBlock.gif        /// <param name="objectString">原始字符串</param>
18InBlock.gif        /// <param name="length">左对齐后的字符串长度</param>
19InBlock.gif        /// <returns>左对齐后的字符串</returns>
20InBlock.gif        /// <example>
21InBlock.gif        /// 如调用方式为PadRightString("123",5);
22InBlock.gif        /// 则返回值为"123~~"
23InBlock.gif        /// </example>
24InBlock.gif        /// <exception cref="InvalidTelegraphStringLengthException">
25InBlock.gif        /// 当参数<paramref name="objectString"/>的长度超出参数<paramref name="length"/>指定的值时抛出
26ExpandedBlockEnd.gif        /// </exception>

27 None.gif          public   static   string  PadRightString( string  objectString,  int  length)
28 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
29InBlock.gif            //原始字符串长度,中文字符按2位计
30InBlock.gif            int objectStringLength = GetLength(objectString);
31InBlock.gif            if (objectString == null || objectStringLength > length)
32ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
33InBlock.gif                throw new InvalidTelegraphStringLengthException();
34ExpandedSubBlockEnd.gif            }

35InBlock.gif            else
36ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
37InBlock.gif                //需自动填充的长度
38InBlock.gif                int suffixLength = length - objectStringLength;
39InBlock.gif                string sunffix = string.Empty;
40InBlock.gif                //不足位数补"~"
41InBlock.gif                for (int i = 0; i < suffixLength; i++)
42ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
43InBlock.gif                    sunffix += "~";
44ExpandedSubBlockEnd.gif                }

45InBlock.gif                return objectString + sunffix;
46ExpandedSubBlockEnd.gif            }

47ExpandedBlockEnd.gif        }
 
48 ExpandedBlockStart.gifContractedBlock.gif     /**/ /// <summary>
49InBlock.gif    /// 获取父页面URL的参数对应值
50InBlock.gif    /// </summary>
51ExpandedBlockEnd.gif    /// <returns></returns>

52 None.gif      protected  Dictionary < string string >  GetParentQueryString()
53 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
54InBlock.gif        Dictionary<stringstring> dic = new Dictionary<stringstring>();
55InBlock.gif        string strParams = Request.UrlReferrer.Query;
56InBlock.gif        if (!string.IsNullOrEmpty(strParams))
57ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
58ExpandedSubBlockStart.gifContractedSubBlock.gif            string[] queryParams = strParams.Substring(1).Split(new char[] dot.gif'&' });
59InBlock.gif            for (int i = 0; i < queryParams.Length; i++)
60ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
61ExpandedSubBlockStart.gifContractedSubBlock.gif                dic.Add(queryParams[i].Split(new char[] dot.gif'=' })[0], queryParams[i].Split(new char[] dot.gif'=' })[1]);
62ExpandedSubBlockEnd.gif            }
            
63ExpandedSubBlockEnd.gif        }

64InBlock.gif        return dic;
65ExpandedBlockEnd.gif    }
    

转载于:https://www.cnblogs.com/jiangshaofen/archive/2007/04/24/724643.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值