你几乎在你的问题中描述了答案。为每个数字定义一个固定的宽度。
int iShardId = 12; // Fixed width of 5
int iTableTypeId = 840; // Fixed width of 5
long lIncremental = 967295; // Fixed width of 10
string sMyId = String.Concat(iShardId.ToString("00000"), iTableTypeId.ToString("00000"), lIncremental.ToString("0000000000"));
然后,您可以稍后解析字符串(通过IHttpModule的或其他)使用正则表达式:
RegEx rMyText = new RegEx(@"/(?<shard>[0-9]{5})(?<table>[0-9]{5})(?<inc>[0-9]{10})/?$");
Match mMyValues = rMyText.Match(Request.Url.AbsolutePath);
if (mMyValues.Success) {
int iShardId = Convert.ToInt32(mMyValues["shard"].Value);
int iTableTypeId = Convert.ToInt32(mMyValues["table"].Value);
long lIncremental = Convert.ToInt64(mMyValues["inc"].Value);
}
else {
//The input didn't match
}
正则表达式的目的是作为一个样本来分析的数字,但很明显,这取决于你如何规划为了实现,你应该调整它,以确保输入被限制为你期望的值,通过使用开始/结束斜线或字符串结尾($)。
是否有任何理由不让每个人都放在URL的单独部分,例如http://mywebsite.com/folders/65535/65535/4294967297 –
是的,对于massy,脸谱,pinterest和所有的大牌球员使用很长的数字,而不是在像文件夹,所以我只是跟随趋势,它看起来更好在我看来 –