字符串替换/注册表操作 [英] String Replace/Registry Manipulation

查看:88
本文介绍了字符串替换/注册表操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


VB.NET 2003只能请


我有一个注册表项(HKCU \Software \Newbie \\ \\ String $

保存XML字符串,如下所示:


< root formID =" preferencesform"郎= QUOT;英语" >< global welcome =" 0"

lang =" british" soundEffects = QUOT; 0" soundTheme = QUOT;默认" stayOnTop =" 0"

autoStart =" 0" />< main>< pos x =" 761" Y =" 277" />< size width =" 240"

height =" 450" />< / main>< chat fontFamily =" tahoma" fontSize =" 12"

inMsgColor =" 255" outMsgColor = QUOT; 3368448" />< video webcam =" undefined"

/>< / root>


我需要从注册表中读取密钥,将''autoStart''值从

0(零)替换为1(一)&使用复选框控件返回。


''自动启动''从角色135开始制作它时零为11个字符

char。 146.我也需要为''stayOnTop''值做这个,但

这两个值将分享相同的方法,只是不同的位置。


如何在不创建临时XML文档的情况下执行此操作,更改它&

写回注册表?


TIA

Hi all,

VB.NET 2003 ONLY PLEASE

I have a registry key (HKCU\Software\Newbie\SomeKey) of type string which
holds an XML string as follows:

<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video webcam="undefined"
/></root>

I need to read the key from the registry, replace the ''autoStart'' value from
0 (zero) to 1 (one) & back using a checkbox control.

''Autostart'' starts at character 135 & the zero is 11 characters on making it
char. 146. I will also need to do this for the ''stayOnTop'' value too, but
both values will share the same method, just different positions.

How do I do this without creating a temporary XML document, changing it &
writing back to the registry?

TIA

推荐答案

尝试使用Replace函数。


将reg值加载到mystring中

替换( mystring,autoStart ="& chr(34)&" 0" chr(34)," autoStart ="&

chr(34)&" ; 1"& chr(34))

将mystring写回reg
Try to use the Replace function.

load reg value into mystring
Replace(mystring, "autoStart=" & chr(34) & "0" & chr(34), "autoStart=" &
chr(34) & "1" & chr(34))
write mystring back to reg


感谢您的回复。我考虑过这样做,但我也在考虑这个问题:


s ="< root formID =" preferencesform"郎= QUOT;英语" >< global welcome =" 0"

lang =" british" soundEffects = QUOT; 0" soundTheme = QUOT;默认" stayOnTop =" 0"

autoStart =" 0" />< main>< pos x =" 761" Y =" 277" />< size width =" 240"

height =" 450" />< / main>< chat fontFamily =" tahoma" fontSize =" 12"

inMsgColor =" 255" outMsgColor = QUOT; 3368448" />< video

webcam =" undefined" />< / root>"


Dim i As Integer = s.IndexOf (autoStart)''i =''a''自动启动

Dim ss As String = s.Substring(i + 11,1).Replace(" 0"," 1")


然后再次整理整个字符串,但是在上面的示例中,'s''在上面的'b'中保留了compulete字符串,现在它开始了只包含''1''


那么,如何将它写回整个字符串?


任何想法?
Thanks for your reply. I thought about doing that, but I was also thinking
on the lines of this:

s = "<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video
webcam="undefined"/></root>"

Dim i As Integer = s.IndexOf("autoStart") '' i = ''a'' of autostart
Dim ss As String = s.Substring(i + 11, 1).Replace("0", "1")

Then concatinating the entire string again, but whereas ''s'' in the example
above held the compulete string at the beginning now it contains just ''1''

So, how to I write it back to the entire string?

Any ideas?


我认为你会发现在执行这两个语句之后,那个s / $
仍然保持while字符串(未更改)并且ss的长度为1和

值为1。


您是否尝试过简单:


s = s。替换(autoStart ="" 0"""," autoStart ="" 1"")


我也不喜欢我真的明白你对使用XmlDocument的抵制,比如

这个:


Dim _doc为新的XmlDocument

_doc.LoadXml( s)

_doc.SelectSingleNode(" // global")。Attributes(" autoStart")。Value =" 1"

_s = _doc.OuterXml

" Newbie Coder" < ne ********* @ spammeplease.com写信息

新闻:%2 **************** @ TK2MSFTNGP03.phx .gbl ...
I think that you will find that after executing those 2 statements, that s
still holds the while string (unchanged) and that ss has a length of 1 and a
value of "1".

Have you tried simply:

s = s.Replace("autoStart=""0""", "autoStart=""1"")

Also I don''t really understand your resistance to using an XmlDocument like
this:

Dim _doc as New XmlDocument
_doc.LoadXml(s)
_doc.SelectSingleNode("//global").Attributes("autoStart").Value = "1"
_s = _doc.OuterXml
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

感谢您的回复。我考虑过这样做,但我也在考虑这个问题:


s ="< root formID =" preferencesform"郎= QUOT;英语" >< global welcome =" 0"

lang =" british" soundEffects = QUOT; 0" soundTheme = QUOT;默认" stayOnTop =" 0"

autoStart =" 0" />< main>< pos x =" 761" Y =" 277" />< size width =" 240"

height =" 450" />< / main>< chat fontFamily =" tahoma" fontSize =" 12"

inMsgColor =" 255" outMsgColor = QUOT; 3368448" />< video

webcam =" undefined" />< / root>"


Dim i As Integer = s.IndexOf (autoStart)''i =''a''自动启动

Dim ss As String = s.Substring(i + 11,1).Replace(" 0"," 1")


然后再次整理整个字符串,但是在上面的示例中,'s''在上面的'b'中保留了compulete字符串,现在它开始了只包含''1''


那么,如何将它写回整个字符串?


任何想法?

Thanks for your reply. I thought about doing that, but I was also thinking
on the lines of this:

s = "<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video
webcam="undefined"/></root>"

Dim i As Integer = s.IndexOf("autoStart") '' i = ''a'' of autostart
Dim ss As String = s.Substring(i + 11, 1).Replace("0", "1")

Then concatinating the entire string again, but whereas ''s'' in the example
above held the compulete string at the beginning now it contains just ''1''

So, how to I write it back to the entire string?

Any ideas?


这篇关于字符串替换/注册表操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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