I am looping character through a memo field but I do not know how to stop the looping. Is there an End-of-field value like the EOF character? Is there a better way to determine the end of a memo field?
Asked
Active
Viewed 128 times
2 Answers
1
If you use foreach
you don't need to worry about it...
string memo = "test";
foreach (var x in memo.ToCharArray())
{
// you code here
}

James Allen
- 819
- 7
- 12
-
I am not familar with the foreach function. What would be the target for the foreach? Can you give me an example? – Hal Metz Apr 15 '11 at 19:38
-
Why the use of `ToCharArray`? – Jim Mischel Apr 15 '11 at 20:16
1
I'm not sure what you mean by a "memo field." Do you mean a string? If so, then you can access the Length
property:
string memo = "hello, world";
for (int i = 0; i < memo.Length; ++i)
{
char c = memo[i];
// do what you want with the character.
}
Or you can use the foreach
as was suggested previously:
foreach (var c in memo)
{
// do what you want with the character
}

Jim Mischel
- 131,090
- 20
- 188
- 351