473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Look for a character in a certain position

KJ
How can you look for a character in a certain position with VB.Net and
if the string length is less than the position have it return and
empty string instead of an error?

Substring returnns an error if the length is less than the position of
the character you want.
Ex. Dim x As String = 'ABCD'
x.Substring(5,1) returns error

I need a way to get the character or not return an error.

I don't want to have to do this

If x.length = 5 then
x.substring(5,1)
End If
Thanks
Nov 21 '05 #1
6 2111
KJ,

I don't want to have to do this

If x.length = 5 then
x.substring(5,1)
End If


This above will fail with an error

If x.lenght > 5 then y = x.substring(5.1)

I do not know shorter solutions.

I hope it helps?

Cor
Nov 21 '05 #2
"KJ" <kl******@hotmail.com> schrieb:
How can you look for a character in a certain position with VB.Net and
if the string length is less than the position have it return and
empty string instead of an error?

Substring returnns an error if the length is less than the position of
the character you want.
Ex. Dim x As String = 'ABCD'
x.Substring(5,1) returns error

I need a way to get the character or not return an error.


Use 'Mid' instead if 'Substring', it won't throw an exception in this case
and will return "".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Herfried,

That was it, I knew it.

:-)

Cor
Nov 21 '05 #4


Wow. I did not know that. Is Mid one of those old VB6 functions that
creeped over to .NET? In my company we are not allowed to use old VB 6
functions like CStr and CInt. Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Bill,
Wow. I did not know that. Is Mid one of those old VB6 functions that
creeped over to .NET? In my company we are not allowed to use old VB 6
functions like CStr and CInt. Thanks


Do you use the = from old VB6 as well not?

CStr and CInt are full dotNet methods, however not in the basic namespace
but in the namespace.
Microsoft.VisualBasic which is sometimes confused with the
Microsoft.VisualBasicCompatibility namespace, whih will be temporaly.

Although I never use the MID. But that is because of the for me confusing
indexing, which start at One while methods not in the basic Net namespace
start with the historical Zero indexer what I am used too.

Cor
Nov 21 '05 #6
"BillGatesFan" <no****@devdex.com> schrieb:
Wow. I did not know that. Is Mid one of those old
VB6 functions that creeped over to .NET?
You are programming VB.NET, not ".NET". Yes, 'Mid' was available in VB6
too, and is still available in VB.NET, and will be available in VB 2005, and
will maybe exist even longer than the .NET Framework will exist.
In my company we are not allowed to use old VB 6
functions like CStr and CInt.


Stupid rules!!

"Use VB.NET, but do not use it!"

Forbidding the use of these functions is simply a sign for the
/incompetence/ of the person who set up these rules.

[Yes, you are granted rights to print out this mail and show it the person
who invented these stupid rules].

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Simon | last post by:
Hi, If I have a string, (variable len), and I am looking for the first position of one char in array starting from position 'x' For example, // the 'haystack' $string = "PHP is great,...
9
by: MSUTech | last post by:
Hello, What is the best way to check each character within a string? For doing something like encryption, where you check character 1 and replace it with a different character.. then check...
1
by: Colin Green | last post by:
OK here's is what I wish to do. I have an XML file that I want to read into an XmlDocument. I then want to be able to interrogate the XmlNodes to find both their start AND end character positions...
2
by: Mike P | last post by:
I want to find a particular character in a string, and then find the length of the string after this point in the string, so that I can do a rightpad on it if it is of a certain length (basically I...
3
by: stormandstress | last post by:
Hi. I'm writing a program that is dependent on the curses library and functions for python, and I'm a little puzzled by the way characters are handled. The basics of the program are that a...
3
by: magix | last post by:
How can I search for occurance of a character in certain position of a string I checked function strchr, but doesn't option to specify position. Thanks. Regards, Magix
8
by: rudra | last post by:
hello friends, in a code i am trying to retrive the machine bit the code. The code is: #include <stdlib.h> #include <stdio.h> #include <string.h> main(){ FILE *stream; char sys,*sysptr; int...
5
by: Andrus | last post by:
I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position...
1
by: KiddoGuy | last post by:
I am trying to build a string character by character. However, when I use the overloaded += or string.append() method, the character replaces the one before it rather than appending to it so I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.