Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2012, 02:02 AM   PM User | #1
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
Arrow Extracting a substring from 1st, 3rd, 5th places in textbox

Hello coding forums, I am having difficulty in figuring out how to extract only certain character, or digits inside a textbox. I have been looking up similar methods but none seem to work for what I want to be done.

I have a textbox called textBox1. I then made a string called
Code:
string total = textBox1.Text
I tried to code a statement which grabs only the 1st, 3rd, 5th, etc of the string but it hasn't worked for me
I've been trying:
Code:
for (int i = 0; i < total.Length; i++)
	{
         textBox1.Text = total ;
	 }
PLEASE help me in figuring this out, and I'll instantly thank you cuz I really need to get this app done tonight before I lose my train of thought in the morning.

sorry mods, you may delete this if you would like. I figured it out using: http://www.dotnetperls.com/substring

sorry for the thread

Last edited by crank01; 02-11-2012 at 04:22 AM..
crank01 is offline   Reply With Quote
Old 02-11-2012, 05:45 AM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
I think you should look at the string class; it would save you a lot of trouble ref
also worth noting in things I've helped you with before you sent me a visual studio .sln file.... this means you have a VERY powerful tool at your disposal; click on an object (for instance "string") not what you named it, but the actual object class you are substantiating... hit F12. It will take you to the object browser and you can look at pretty much all the info you need WRT that class... also PLEASE peruse the msdn library... that link is a sub-link of the msdn library and it has example code for almost every class- if you ever have problems finding it in google usually the object + class + C# will give you the first hit as the msdn library
eg
Code:
string class C#
first hit gave msdn 1.1 framework (drop down switches to 4 or w/e)
second link is .net 4 framework
that library is VERY useful!!!!!!! help yourself and get comfy in there!
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
crank01 (02-11-2012)
Old 02-11-2012, 10:52 AM   PM User | #3
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
Quote:
Originally Posted by alykins View Post
I think you should look at the string class; it would save you a lot of trouble ref
also worth noting in things I've helped you with before you sent me a visual studio .sln file.... this means you have a VERY powerful tool at your disposal; click on an object (for instance "string") not what you named it, but the actual object class you are substantiating... hit F12. It will take you to the object browser and you can look at pretty much all the info you need WRT that class... also PLEASE peruse the msdn library... that link is a sub-link of the msdn library and it has example code for almost every class- if you ever have problems finding it in google usually the object + class + C# will give you the first hit as the msdn library
eg
Code:
string class C#
first hit gave msdn 1.1 framework (drop down switches to 4 or w/e)
second link is .net 4 framework
that library is VERY useful!!!!!!! help yourself and get comfy in there!
cool I never knew about the f12 shortcut thx, and I'll take a look at the msdn library some more. I've been using it alot to solve many problems I have.

now I already solved what I was trying to do, but out of curiosity, how would have you done it? My way was probably the quick n dirty method, but if you know a better way plz tell.
crank01 is offline   Reply With Quote
Old 02-11-2012, 05:57 PM   PM User | #4
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
I'm not really all to sure what exactly you were trying to do- what if what was in those "sub string" sections was not what you were expecting?
eg
expecting 123alykins456
so sub-strings go to
~123
~alykins
~456
but what if it got
1aly234ki5n6s
now the sub-strings are
~1al
~y234ki5
~n6s
now what?

I do not know what means you are trying to accomplish, if validating you can make an expression and validate it that way, if you are trying to see if a string contains something based on a set of "constraints" you could do something like...
Code:
private string[] constraints = new string[3] {"123", "alykins", "456"};
private string order = null;
private bool[] validatedStrings = new bool[3] {false, false, false};
private bool StringEquals = false;

public void validateString(string text){
for(int i=0; i<constraints.length; i++){
validatedStrings[i] = text.Contains(constraints[i]);
}
foreach(string s in constraints){
order+=s;
}
StringEquals = (String.Compare(order,text,true))? true : false;
}
but again i have no clue what end you are trying to achieve would alter how I would do it etc...
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 02-11-2012, 06:51 PM   PM User | #5
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
well given a string of digits from a textBox, I converted the text-->toString, and then using
Code:
string sub = input.Substring(0, 1);
I was able to take Only the first digit from the string, then using
Code:
string sub = input.Substring(0, 1) + input.Substring(2, 1);
I was able to take the 3rd digit/character of the string and turn it into the string called sub.

This way of coding is possibly not looked well upon, but who knows. It worked for me
crank01 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:47 AM.


Advertisement
Log in to turn off these ads.