How to read character by character right to left?
I hope and you can help me please, I have a label that shows a value in binary.
Example: "1000010101"
, this data, I'm reading it with an inverted for. That is, starting from right to left, the binary number is dynamic, so it will not always be the same.
Until now this is my idea, but it does not give me any value
for (int i = lbl_conversion.Text.Length; i > 0; i--)
if (st[i] == 1)
MessageBox("1");
else
MessageBox("0");
What I would like is to read character by character from left to right and know if it is "1"
or "0"
and then make a comparison, could someone support me to get that result?
Thank you.
c# string
add a comment |
I hope and you can help me please, I have a label that shows a value in binary.
Example: "1000010101"
, this data, I'm reading it with an inverted for. That is, starting from right to left, the binary number is dynamic, so it will not always be the same.
Until now this is my idea, but it does not give me any value
for (int i = lbl_conversion.Text.Length; i > 0; i--)
if (st[i] == 1)
MessageBox("1");
else
MessageBox("0");
What I would like is to read character by character from left to right and know if it is "1"
or "0"
and then make a comparison, could someone support me to get that result?
Thank you.
c# string
4
int i = lbl_conversion.Text.Length - 1;
please, note-1
;i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
1
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39
add a comment |
I hope and you can help me please, I have a label that shows a value in binary.
Example: "1000010101"
, this data, I'm reading it with an inverted for. That is, starting from right to left, the binary number is dynamic, so it will not always be the same.
Until now this is my idea, but it does not give me any value
for (int i = lbl_conversion.Text.Length; i > 0; i--)
if (st[i] == 1)
MessageBox("1");
else
MessageBox("0");
What I would like is to read character by character from left to right and know if it is "1"
or "0"
and then make a comparison, could someone support me to get that result?
Thank you.
c# string
I hope and you can help me please, I have a label that shows a value in binary.
Example: "1000010101"
, this data, I'm reading it with an inverted for. That is, starting from right to left, the binary number is dynamic, so it will not always be the same.
Until now this is my idea, but it does not give me any value
for (int i = lbl_conversion.Text.Length; i > 0; i--)
if (st[i] == 1)
MessageBox("1");
else
MessageBox("0");
What I would like is to read character by character from left to right and know if it is "1"
or "0"
and then make a comparison, could someone support me to get that result?
Thank you.
c# string
c# string
edited Nov 12 '18 at 19:27
Dmitry Bychenko
109k1094135
109k1094135
asked Nov 12 '18 at 19:12
Ric_hcRic_hc
1608
1608
4
int i = lbl_conversion.Text.Length - 1;
please, note-1
;i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
1
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39
add a comment |
4
int i = lbl_conversion.Text.Length - 1;
please, note-1
;i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
1
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39
4
4
int i = lbl_conversion.Text.Length - 1;
please, note -1
; i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
int i = lbl_conversion.Text.Length - 1;
please, note -1
; i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
1
1
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39
add a comment |
2 Answers
2
active
oldest
votes
Since string
s are zero based, correct for
loop will be
// Note "- 1" and ">="
for (int i = lbl_conversion.Text.Length - 1; i >= 0; --i)
if (st[i] == '1') //DONE: comparing with character, not integer
MessageBox("1");
else
MessageBox("0");
Or you can just Reverse
the string (with a help of Linq):
// Let's read each character in reversed order
foreach (char c in lbl_conversion.Text.Reverse())
MessageBox(c.ToString());
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
add a comment |
just one more (similar to prev posted)
string s="10111011";
s.Reverse().ToList().ForEach(ch=>Console.WriteLine(ch=='1'?"A":"0"));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268627%2fhow-to-read-character-by-character-right-to-left%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since string
s are zero based, correct for
loop will be
// Note "- 1" and ">="
for (int i = lbl_conversion.Text.Length - 1; i >= 0; --i)
if (st[i] == '1') //DONE: comparing with character, not integer
MessageBox("1");
else
MessageBox("0");
Or you can just Reverse
the string (with a help of Linq):
// Let's read each character in reversed order
foreach (char c in lbl_conversion.Text.Reverse())
MessageBox(c.ToString());
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
add a comment |
Since string
s are zero based, correct for
loop will be
// Note "- 1" and ">="
for (int i = lbl_conversion.Text.Length - 1; i >= 0; --i)
if (st[i] == '1') //DONE: comparing with character, not integer
MessageBox("1");
else
MessageBox("0");
Or you can just Reverse
the string (with a help of Linq):
// Let's read each character in reversed order
foreach (char c in lbl_conversion.Text.Reverse())
MessageBox(c.ToString());
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
add a comment |
Since string
s are zero based, correct for
loop will be
// Note "- 1" and ">="
for (int i = lbl_conversion.Text.Length - 1; i >= 0; --i)
if (st[i] == '1') //DONE: comparing with character, not integer
MessageBox("1");
else
MessageBox("0");
Or you can just Reverse
the string (with a help of Linq):
// Let's read each character in reversed order
foreach (char c in lbl_conversion.Text.Reverse())
MessageBox(c.ToString());
Since string
s are zero based, correct for
loop will be
// Note "- 1" and ">="
for (int i = lbl_conversion.Text.Length - 1; i >= 0; --i)
if (st[i] == '1') //DONE: comparing with character, not integer
MessageBox("1");
else
MessageBox("0");
Or you can just Reverse
the string (with a help of Linq):
// Let's read each character in reversed order
foreach (char c in lbl_conversion.Text.Reverse())
MessageBox(c.ToString());
answered Nov 12 '18 at 19:18
Dmitry BychenkoDmitry Bychenko
109k1094135
109k1094135
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
add a comment |
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
Excellent answer Dmity, Thanks...
– Ric_hc
Nov 12 '18 at 20:37
add a comment |
just one more (similar to prev posted)
string s="10111011";
s.Reverse().ToList().ForEach(ch=>Console.WriteLine(ch=='1'?"A":"0"));
add a comment |
just one more (similar to prev posted)
string s="10111011";
s.Reverse().ToList().ForEach(ch=>Console.WriteLine(ch=='1'?"A":"0"));
add a comment |
just one more (similar to prev posted)
string s="10111011";
s.Reverse().ToList().ForEach(ch=>Console.WriteLine(ch=='1'?"A":"0"));
just one more (similar to prev posted)
string s="10111011";
s.Reverse().ToList().ForEach(ch=>Console.WriteLine(ch=='1'?"A":"0"));
answered Nov 12 '18 at 19:43
AndrewFAndrewF
333
333
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268627%2fhow-to-read-character-by-character-right-to-left%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
int i = lbl_conversion.Text.Length - 1;
please, note-1
;i >= 0
– Dmitry Bychenko
Nov 12 '18 at 19:14
1
You should be getting an exception, which should be providing you a big clue about what you're doing wrong here.
– Clockwork-Muse
Nov 12 '18 at 19:14
Even if you do get this working, I'm not sure how 10 separate message boxes are useful. What are you actually trying to do with this?
– crashmstr
Nov 12 '18 at 19:17
See also C# read string from back to end
– Heretic Monkey
Nov 12 '18 at 19:18
"and then make a comparison" comparing to what...?
– DaniDev
Nov 12 '18 at 19:39