小白又来了 简单关联 求思路 帮顶给分 在线等

zjybushiren88888 2008-12-03 10:44:59
string a="10101" string b="11000" enmu{a=1,b=2,c=3,d=4,e=5}
结果a关联的value=ace b关联的value=ab

10101 1代表true 0代表false

高手帮助 最好有实例

...全文
164 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjybushiren88888 2008-12-03
  • 打赏
  • 举报
回复
感谢大家 我是把enmu的value让用户选择 最后保存 得到string 101010... 1代表有选 0代表无
lq20051610211 2008-12-03
  • 打赏
  • 举报
回复
帮顶~
lijunfeng 2008-12-03
  • 打赏
  • 举报
回复
不好意思,上面的第一个"enum"写错了
lijunfeng 2008-12-03
  • 打赏
  • 举报
回复
看大家都是用enum啊,那这样的话我再改一下吧,不用数组了,就用enum

enmu list {a=1,b=2,c=3,d=4,e=5}
string getString(string a)
{
string strResult = "";
for(int i = 0; i < a.length; i++)
{
strResult += (a[i] == '1' ? ((list)(i+1)).ToString() : "");
}
return strResult;
}

不过楼主这个东西是用在哪里的啊,为什么要这样设计呢?
diffmaker 2008-12-03
  • 打赏
  • 举报
回复
又一种风格,:)


using System;
using System.Collections.Generic;
using System.Text;
namespace CATesting
{
enum CharCol
{
a,
b,
c,
d,
e
}
class Program
{
static void Main(string[] args)
{
string a = "10101";
string b = "11000";
string c = "00101";
Console.WriteLine(ConvertString(a));
Console.WriteLine(ConvertString(b));
Console.WriteLine(ConvertString(c));
Console.ReadKey();
}

private static string ConvertString(string s)
{
string rtn = string.Empty;
for (int i = 0; i < s.Length; i++)
{
int j = s[i] == '0' ? 0 : (i + 1);
if (j > 0) rtn += (CharCol)(j - 1);
}
return rtn;
}
}
}
ysj52zqq 2008-12-03
  • 打赏
  • 举报
回复
up
dq512000 2008-12-03
  • 打赏
  • 举报
回复
果然风格各不相同
MARK下
GTX280 2008-12-03
  • 打赏
  • 举报
回复

public enum Enum1
{
a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
}
string str = "10101";
string GetValue(string str)
{

int count = 0;
string value = "";
foreach (char ch in str)
{
count++;
if (ch == '0')
{
continue;
}else
{
value += ((Enum1)count).ToString();
}
}
return value;
}
bloodish 2008-12-03
  • 打赏
  • 举报
回复
上面变量写错了,sorry.
Relation r = (Relation)Convert.ToInt64(a, 2);
string str = r.ToString();
bloodish 2008-12-03
  • 打赏
  • 举报
回复

[Flags]
public enum Relation : long
{
a = 16,
b = 8,
c = 4,
d = 2,
e = 1,
}

string a = "10101";
Relation ir = (Relation)Convert.ToInt64(a, 2);
string str = r.ToString();


str = "a, c, e";
如果要转成楼主想要的格式...
str = str.Replace(", ", string.Empty);
diffmaker 2008-12-03
  • 打赏
  • 举报
回复
帮顶,赚一分
simonezhlx 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 zjybushiren88888 的帖子:]
string a="10101" string b="11000" enmu{a=1,b=2,c=3,d=4,e=5}
[/Quote]
string a,b都是二进制?枚举值中a,b,c,d,e的值是十进制?
simonezhlx 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 zjybushiren88888 的帖子:]
string a="10101" string b="11000" enmu{a=1,b=2,c=3,d=4,e=5}
结果a关联的value=ace b关联的value=ab

10101 1代表true 0代表false

高手帮助 最好有实例
[/Quote]
没搞清楚
gomoku 2008-12-03
  • 打赏
  • 举报
回复

public class Test
{
static void Main()
{
string a = "10101";
string b = "11000";
string c = "00011";

Console.WriteLine(GetMyDetail(a));
Console.WriteLine(GetMyDetail(b));
Console.WriteLine(GetMyDetail(c));

Console.ReadLine();
}

static string GetMyDetail(string s)
{
int value = Convert.ToInt32(s, 2);
return ((My)value).ToString();
}
}

[Flags]
enum My
{
a = 16,
b = 8,
c = 4,
d = 2,
e = 1
}


You might choose to use Enum flags. It is easy to understand and implement.
hul19830820 2008-12-03
  • 打赏
  • 举报
回复
帮顶
vrhero 2008-12-03
  • 打赏
  • 举报
回复
[Flags]
enmu 要学会看文档
{
a=0x1,
b=0x2,
c=0x4,
d=0x8,
e=0x16
}
lijunfeng 2008-12-03
  • 打赏
  • 举报
回复

string getString(string a)
{
string[] strList = {"a","b","c","d","e"};
string strResult = "";
for(int i = 0; i < a.length; i++)
{
strResult += (a[i] == '1' ? strList[i] : "");
}
return strResult;
}

上面代码没有测试,应该差不多了。
lijunfeng 2008-12-03
  • 打赏
  • 举报
回复
不如把enmu换成数组,如:{"a","b","c","d","e"},然后就是测位来取值了
jiang_jiajia10 2008-12-03
  • 打赏
  • 举报
回复
帮顶
Old_Mouse 2008-12-03
  • 打赏
  • 举报
回复
先帮顶在看。

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧