- Home /
Question by
MarkSchramm · Aug 25, 2014 at 04:27 AM ·
stringdictionaryreplacecharregex
Replace chars in String with a Dictionary and avoid order-sensitive problems
Hi,
I am trying to replace chars in a string. The string is:
TrueæRoll*Pitch*Yaw*Thruster*#15*17*19*20*#14*16*18*-1*#4¿-99*-99*-99*-99*¿-99*-99*-99*-99*¿-99*-99*-99*-99*æFalse*False*False*False*æ24¿Fire*Missile*Boost/Darkfield*TargetShip*Forward*Back*Left*Right*SpinLeft*SpinRight*ResetView*Scoreboard*VoiceChatTeam*VoiceChatAll*Roll+*Roll-*Pitch+*Pitch-*Yaw+*Yaw-*Thruster+*Thruster-*Jump2*ToggleMenu*#Space*LeftAlt*U*J*W*S*A*D*Q*E*R*Tab*V*B*D*A*W*S*E*Q*I*K*LeftShift*Escape*#None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*#Space*LeftAlt*U*J*W*S*A*D*Q*E*R*Tab*V*B*D*A*W*S*E*Q*I*K*LeftShift*Escape*#None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*None*æFire*Missile*Boost/Darkfield*TargetShip*Forward*Back*Left*Right*SpinLeft*SpinRight*ResetView*Scoreboard*VoiceChatTeam*VoiceChatAll*Roll+*Roll-*Pitch+*Pitch-*Yaw+*Yaw-*Thruster+*Thruster-*Jump2*ToggleMenu*¿Space*LeftAlt*U*J*W*S*A*RightArrow*Q*E*R*Tab*V*B*D*A*W*S*E*Q*I*K*None*Escape*¿None*None*None*None*None*None*None*LeftArrow*None*None*Joystick1Button10*Joystick1Button9*None*None*None*None*None*None*None*None*None*None*None*Joystick1Button11*¿**********************Joy1 Axis 2-**¿**************Joy1 Axis 1+*Joy1 Axis 1-*Joy1 Axis 2-*Joy1 Axis 2+*Joy1 Axis 3+*Joy1 Axis 3-*Joy1 Axis 4+****¿Space*LeftAlt*U*J*W*S*A*RightArrow*Q*E*R*Tab*V*B*D*A*W*S*E*Q*I*K*LeftShift*Escape*¿None*None*None*None*None*None*None*LeftArrow*None*None*Joystick1Button10*Joystick1Button9*None*None*None*None*None*None*None*None*None*None*None*Joystick1Button11*ææ
I do have all the substitutions in a dictionary:
joystick1 => joystick3
joystick2 => joystick1
joystick3 => joystick2
If I am replacing it the naive way with a for loop for over the dictionary items, the whole thing becomes order sensitive, i.e. I will replace already substituted chars in further lop iterations.
Anyone got an idea how to solve this? I have found several solutions using regex and dictionaries, but they all required .NET libraries that are not available in Unity's C#
Comment