C#中的字母数字增量

编程入门 行业动态 更新时间:2024-10-25 20:27:58
本文介绍了C#中的字母数字增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要增加数据库中的产品代码(smthg lyk"BK001"). 所以我写了一条sql语句,并从表n中获取了MAX值,并尝试使用(来自C#的字母数字增量,由Sandip Dalvi Tung)的逻辑对其进行递增. dsnt的工作显示了我从sql语句中获得的与gt值相同的数量. 我将sql语句("BK001")中的值gt作为字符串传递给NxtKeyCode方法 ****递增类代码********************************

I need to increment a product code (smthg lyk " BK001 ") which is in a database. so i wrote a sql statement and got the MAX value from the table n tried to increment it using the logic from ( Alphanumeric increment in C# By Sandip Dalvi Tung) ... bt wen retrive the max value n send it to the below class it dsnt work is shows the same amount which i gt from the sql statement as the MAX value. i passed the value i gt from the sql statement ("BK001") as a string to the NxtKeyCode method ****increment class code********************************

public string NxtKeyCode(string KeyCode) { byte[] ASCIIValues = ASCIIEncoding.ASCII.GetBytes(KeyCode) ; int StringLength = ASCIIValues.Length ; bool isAllZed = true; bool isAllNine = true; //Check if all has ZZZ.... then do nothing just return empty string. for(int i =0; i < StringLength-1; i++) { if(ASCIIValues[i] != 90) { isAllZed = false; break; } } if(isAllZed && ASCIIValues[StringLength-1] == 57) { ASCIIValues[StringLength-1] = 64; } // Check if all has 999... then make it A0 for(int i =0; i < StringLength; i++) { if(ASCIIValues[i] != 57) { isAllNine = false; break; } } if(isAllNine) { ASCIIValues[StringLength-1] = 47; ASCIIValues[0] = 65; for(int i =1; i < StringLength-1; i++) { ASCIIValues[i] = 48; } } for(int i = StringLength; i > 0; i--) { if(i-StringLength == 0) { ASCIIValues[i-1] +=1; } if(ASCIIValues[i-1] == 58) { ASCIIValues[i-1] = 48; if(i-2 ==-1) { break; } ASCIIValues[i-2] += 1; } else if(ASCIIValues[i-1] == 91) { ASCIIValues[i-1] = 65; if(i-2 ==-1) { break; } ASCIIValues[i-2] += 1; } else { break; } } KeyCode = ASCIIEncoding.ASCII.GetString(ASCIIValues); return KeyCode; } public string NxtKeyCod(string KeyCode) { //int startint = KeyCode.IndexOf("0123456789",0,1); StringBuilder sb = new StringBuilder(); //Regex digitregex = new Regex("^[A-Z])"); //KeyCode = digitregex.Replace(KeyCode, ""); return KeyCode;

****************************************************** ********************* 请任何人能帮助我即时完成一个项目 谢谢 [edit:rjm]将代码放在< pre></pre>中标记以提高可读性[/edit:rjm]

*********************************************************************** please can anyone help me im stuck with a project thank you [edit:rjm]Placed the code within <pre></pre> tags to improve readability[/edit:rjm]

推荐答案

我不知道您如何对此进行测试/调试,但是当我将"BK001"传递给方法将返回字符串"BK002". I don''t know how you tested/debugged this but when I pass "BK001" to the NxtKeyCode() method it returns the string "BK002".

是 C#中的字母数字增量 [ ^ ]代码可以正常工作 Yup Alphanumeric increment in C#[^] The code works fine

您确定使用的是NxtKeyCode()函数,而不是下面称为NxtKeyCod()的函数(注意不是"e"),该函数什么也不做,只是返回已传递的内容来吗? 来自理查德·M(Richard M):我认为这个显而易见的问题不值得提出,但我敢打赌您是对的. Are you sure you''re using the NxtKeyCode() function and not the one below called NxtKeyCod() (note no ''e'') which does nothing but return what is passed to it? From Richard M: I didn''t think this obvious question worth asking, but I am willing to bet you are right.

更多推荐

C#中的字母数字增量

本文发布于:2023-11-30 09:57:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增量   字母   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!