【50分】一个很让人汗颜的初级问题,同志们帮忙

cnwhitewolf 2008-05-27 01:33:36
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";

如何把str 转换为 "\u5f00\u53d1\u8bed\u8a00";

由于反斜杠是转义字符,汗颜,不知道如何操作

...全文
647 40 打赏 收藏 举报
写回复
用AI写文章
40 条回复
切换为时间正序
请发表友善的回复…
发表回复
Guo_881017163 2011-01-12
  • 打赏
  • 举报
回复
开始向各位学习!
mxftzjz45 2008-06-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wwbjj007 的回复:]
引用 2 楼 namhyuk 的回复:
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";

string strNew = str.Replace(@"\\", @"\");
Response.Write(strNew);
[/Quote]

嗯
觉得也是
不过还有点看不懂
xzqnwcf 2008-05-28
  • 打赏
  • 举报
回复
同意37楼
wuyi8808 2008-05-27
  • 打赏
  • 举报
回复
// 发现一个更简单的方法:System.Text.RegularExpressions.Regex.Unescape()

class Test
{
static void Main()
{
string str = @"\x41 B C \r\n\u5f00\u53d1\u8bed\u8a00aa";
string str1 = System.Text.RegularExpressions.Regex.Unescape(str);
System.Console.WriteLine("[{0}] -> [{1}]", str, str1);
}
}
/* 程序输出:
[\x41 B C \r\n\u5f00\u53d1\u8bed\u8a00aa] -> [A B C
开发语言aa]
*/
hwk5 2008-05-27
  • 打赏
  • 举报
回复
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";
程序中处理为 \u5f00\u53d1\u8bed\u8a00
LZ想要的是什么结果?
huifeidebaobao 2008-05-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wwbjj007 的回复:]
引用 2 楼 namhyuk 的回复:
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";

string strNew = str.Replace(@"\\", @"\");
Response.Write(strNew);
[/Quote]
就这个
ericzhangbo1982111 2008-05-27
  • 打赏
  • 举报
回复
CompilerResults
这个。。很好很强大 。
cnwhitewolf 2008-05-27
  • 打赏
  • 举报
回复
非常感谢大家,
特别感谢wuyi8808,问题解决!!!!
Jinglecat 2008-05-27
  • 打赏
  • 举报
回复
看不懂,明明就是需要 \\
ProjectDD 2008-05-27
  • 打赏
  • 举报
回复
\\还用转吗?它自己必须这样啊,自己就转了\是转义符号啊等于是说


@"x:\a\b\c" = "x:\\a\\b\\c";
wuyi8808 2008-05-27
  • 打赏
  • 举报
回复
using System; 
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Reflection;

class Test
{
static void Main()
{
string s = @"\x41 B C \u5f00\u53d1\r\n\""换行\""\x8bed\u8a00aa";
string str1 = Convert(s);
Console.WriteLine("[{0}] -> [{1}]", s, str1);
}

static string Convert(string s)
{
return (new MyString(s)).Parse();
}
}

sealed class MyString
{
object instance;
MethodInfo method;

public MyString(string s)
{
string code = string.Format("sealed class MyString{{public string Parse(){{return \"{0}\";}}}}", s);
CompilerParameters p = new CompilerParameters();
p.GenerateInMemory = true;
CompilerResults cr = new CSharpCodeProvider().CompileAssemblyFromSource(p, code);
instance = cr.CompiledAssembly.CreateInstance("MyString");
method = instance.GetType().GetMethod("Parse");
}

public string Parse()
{
return (string)method.Invoke(instance, null);
}
}

/* 程序输出:
[\x41 B C \u5f00\u53d1\r\n\"换行\"\x8bed\u8a00aa] -> [A B C 开发
"换行"语言aa]
*/
tianwei262 2008-05-27
  • 打赏
  • 举报
回复
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";
string str1=str.Replace("\\",@"\");
Console.WriteLine(str1);
HarleyTung 2008-05-27
  • 打赏
  • 举报
回复
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";

string strNew = str.Replace(@"\\", @"\");
Response.Write(strNew);
wuyi8808 2008-05-27
  • 打赏
  • 举报
回复
using System; 
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Reflection;

class Test
{
static void Main()
{
string str = @"\u5f00\u53d1\r\n\""换行\""\x8bed\u8a00";
string str1 = Convert(str);
Console.WriteLine("[{0}] -> [{1}]", str, str1);
}

static string Convert(string s)
{
return (new MyString(s)).Parse();
}
}

sealed class MyString
{
object instance;
MethodInfo method;

public MyString(string expression)
{
string className = "MyString";
string methodName = "Parse";
string code = string.Format("using System;sealed class {0}{{public string {1}(){{return \"{2}\";}}}}",
className, methodName, expression);
CompilerParameters p = new CompilerParameters();
p.GenerateInMemory = true;
CompilerResults cr = new CSharpCodeProvider().CompileAssemblyFromSource(p, code);
if(cr.Errors.Count > 0)
{
string msg = "MyString(\"" + expression + "\"): \n";
foreach (CompilerError err in cr.Errors) msg += err.ToString() + "\n";
throw new Exception(msg);
}
instance = cr.CompiledAssembly.CreateInstance(className);
method = instance.GetType().GetMethod(methodName);
}

public string Parse()
{
return (string)method.Invoke(instance, null);
}
}

/* 程序输出:
[\u5f00\u53d1\r\n\"换行\"\x8bed\u8a00] -> [开发
"换行"语言]
*/
wangfeizjk 2008-05-27
  • 打赏
  • 举报
回复
str.Replace("\\\\","\\"); 用这个试试
lijingziyou 2008-05-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 prewin 的回复:]
都说的麻烦了,其实LZ意思用一个@就满足了
string str = @"\u5f00\u53d1\u8bed\u8a00";
[/Quote]
wuhaiwuya 2008-05-27
  • 打赏
  • 举报
回复
str=@"\a\b\b"
aisiliuzhou 2008-05-27
  • 打赏
  • 举报
回复
我顶啊!
waslee 2008-05-27
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 wuyi8808 的回复:]
我猜LZ是要实现这个目的吧:(至于怎么实现,正在考虑中)

C# codeusing System;

class Test
{
static void Main()
{
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";
string str1 = Convert(str);
Console.WriteLine("[{0}] -> [{1}]", str, str1);
}

static string Convert(string s)
{
return "\u5f00\u53d1\u8bed\u8a00";
}
}
/* 程序输出:
[\u5f00\u53d1\u8bed\u8a0…
[/Quote]
wuyi8808 2008-05-27
  • 打赏
  • 举报
回复
我猜LZ是要实现这个目的吧:(至于怎么实现,正在考虑中)
using System;

class Test
{
static void Main()
{
string str = "\\u5f00\\u53d1\\u8bed\\u8a00";
string str1 = Convert(str);
Console.WriteLine("[{0}] -> [{1}]", str, str1);
}

static string Convert(string s)
{
return "\u5f00\u53d1\u8bed\u8a00";
}
}
/* 程序输出:
[\u5f00\u53d1\u8bed\u8a00] -> [开发语言]
*/
加载更多回复(20)
内容概要:本文围绕【复现IEEE二区文献】基于状态空间表示与组件连接法的构网型逆变器统一小信号建模框架研究,提出了一种适用于多控制策略构网型逆变器的小信号建模方法。该方法结合状态空间建模理论与组件连接法(Component Connection Method),实现了对复杂逆变器系统动态特性的精确描述,尤其适用于分析系统在不同运行工况下的稳定性。通过Matlab代码实现,构建了包含控制环路、滤波器、锁相环等关键模块的完整小信号模型,并利用特征值分析与模态参与度评估系统稳定性,解决了传统建模方法在面对多时间尺度、强耦合非线性控制结构时建模困难、精度不足的问题。研究还探讨了关键控制参数对系统稳定边界的影响,为构网型逆变器的参数整定与优化设计提供了理论依据和技术支撑。; 适合人群:具备电力电子、自动控制理论基础,从事新能源发电、微电网、电力系统稳定性研究的研究生、科研人员及工程技术人员,尤其适合致力于高水平期刊论文复现与仿真实践的科研工作者。; 使用场景及目标:① 掌握构网型逆变器统一小信号建模的核心方法,复现IEEE二区高水平文献成果;② 理解状态空间法与组件连接法在复杂电力电子系统建模中的集成应用;③ 利用Matlab进行特征值分析与稳定性判据研究,支撑科研仿真与论文写作;④ 为多逆变器并联系统、微电网稳定性分析等课题提供建模工具与技术路线参考。; 阅读建议:建议读者结合Matlab代码与文中建模流程逐步调试,重点关注各子模块状态方程的推导与系统整体矩阵组装过程,深入理解控制参数对系统极点分布的影响规律,建议配合其他稳定性分析案例进行对比学习以加深理解。
内容概要:WiFiSupply斯普莱WFS7000XB52AX5G是一款高性能、工业级的5G全网通+双频WIFI6无线AP基站,支持5G与工业大功率Wi-Fi链路无缝切换与带宽聚合,具备高达2974Mbps的双频带宽和1000Mbps以上的实际吞吐量。设备采用MIMO 4T4R架构,支持OFDMA、AI智能FastRoaming等先进技术,实现低至20ms的漫游切换延迟和超远传输距离(点对点桥接可达150公里以上)。产品具备IP68防水、-45~85℃宽温运行、多重看门狗、防浪涌、防静电等工业级防护设计,适用于复杂恶劣环境。支持胖瘦AP模式、多种认证与管理方式(含云平台、API接口),并集成丰富的网络安全与QoS功能,适用于智慧物流、工业4.0、巡检机器人、无人机、车载船舶等多种场景。; 适合人群:从事工业物联网、智能制造、自动化物流、智能交通等领域的网络工程师、系统集成商、设备制造商及技术决策人员。; 使用场景及目标:①实现移动设备(如AGV/AMR/巡检机器人)在高速移动中的零丢包、低延迟无线漫游;②在无固定网络覆盖区域构建高带宽、高可靠的远距离无线通信链路;③为5G与工业Wi-Fi双链路备份与聚合提供一体化解决方案,保障关键业务连续性;④在复杂电磁环境下实现稳定、安全的数据传输与远程控制。; 阅读建议:本产品技术参数详尽,建议结合具体应用场景重点关注其无线性能、漫游技术、供电方式与安装选项,并参考官方提供的管理平台与API接口文档进行系统集成与远程运维规划。

111,128

社区成员

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

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

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