生成4个字符串 [英] Generate 4 Character String

查看:63
本文介绍了生成4个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建SMS应用程序,用于将重要活动通知用户.但问题是无法跟踪有关短信的回复消息.我正在从同一号码发送和接收短信.
我以为是生成4个字符串并随同
这样的消息一起发送
<SMS message><space><GeneratedKey>

当用户使用生成的键值发送答复时

<GeneratedKey><space><SMS message>

使用该键值,我可以找到给定SMS的回复消息.

由于该键需要易于输入,因此我认为可以从数字和字符生成序列,并且键长为4.

每个字符序列都一样.

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

生成的密钥应如下所示.

I''m creating SMS application for notify users about important activities. but the problem is there is no way to track for reply messages for relevant sms. I''m sending and receiving SMS from same number.
What i thought was generate 4 Character string and sending with the message like

<SMS message><space><GeneratedKey>

When user send reply with that generated Key value

<GeneratedKey><space><SMS message>

Using that key value I can find the reply messages for given SMS.

Since that key is need to be easy to enter I thought to generate sequence from both digits and characters and key length is 4.

each character sequence goes like.

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

generated keys should be like below.

0000<br />
0001<br />
0002<br />
...<br />
...<br />
0009<br />
000A<br />
000B<br />
....<br />
000Z<br />
0010<br />
....



在发送SMS之前,我将使用下一个键将记录添加到表中,之后,我将使用该键值发送消息.

专家请您对这种方法提出想法,也可以请我帮助从c#生成下一个键值吗?



Before sending SMS i''m going to add record to table with next key and after that I''m sending message with that key value.

Experts please give your thoughts on this approach and also can you please help me to generate next key value from c#?

推荐答案

这就是我实现的

This is what I implemented

String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

private static String Increment(String s)
{
    if (string.IsNullOrEmpty(s))
        return string.Empty;

    char lastChar = s[s.Length - 1];
    string fragment = s.Substring(0, s.Length - 1);

    if (chars.IndexOf(lastChar) < 35)
    {
        lastChar = chars[chars.IndexOf(lastChar) + 1];
        return fragment + lastChar;
    }

    return Increment(fragment) + '0';
}


这篇关于生成4个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆