473,394 Members | 1,734 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,394 software developers and data experts.

How to check if a string starts with a certain character

Hello,

Can someone tell me how to check if a string variable starts with a
dash.
' - '

Thanks,
Gary.

May 2 '06 #1
6 8400
Have a look at the docs.
You can use StartsWith method

HTH
Kalpesh

May 2 '06 #2
Ask the string variable all string variables have a StartsWith Method that
returns true or false
ie
string strvar = "-abc";

strvar.StartsWith("-") will return true.
"ga********@myway.com" wrote:
Hello,

Can someone tell me how to check if a string variable starts with a
dash.
' - '

Thanks,
Gary.

May 2 '06 #3
Sorry I should have been more specifc. I've already discovered
..startswith but can't see how to use it properly.

I want to do something while a string DOES NOT start with a certain
value.

i.e. while the string does not start with a dash '-' do something,
otherwise stop.

any ideas,

thanks.

May 2 '06 #4
line = sr.ReadLine();
while ((line.StartsWith("-") = false))
{
Console.WriteLine(line);
line = sr.ReadLine();
}

this is what i tried, but i get an error when i add the = false to the
while condition...

May 2 '06 #5
you are using = when you mean ==

while(!StartsWith("-")) is neater, and IMO clearer

Marc
May 2 '06 #6
Any comparaison must use "==", not "="
And any caracter can be read in a string with the "[]"
But of course, in that case, be sure length > 0 or an error will be throw.

<ga********@myway.com> a écrit dans le message de news:
11**********************@y43g2000cwc.googlegroups. com...
line = sr.ReadLine();
while ((line.StartsWith("-") = false))
{
Console.WriteLine(line);
line = sr.ReadLine();
}

this is what i tried, but i get an error when i add the = false to the
while condition...

May 2 '06 #7

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

Similar topics

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...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
10
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
11
by: jcrouse | last post by:
I’m using VB .Net 2003. I am reading a file into memory. Here is a sniplet of the file ” section. I have the code returning what character the string “” starts at but don’t know the...
3
by: Kuups | last post by:
Hi! I have a question regarding the count if character within a string like for example I have a string of e.g. 123#123# I would like to determine what is the code? of getting the # sign
1
by: Dino Buljubasic | last post by:
Hi, I am using lots of string comparisons using String.StartsWith(subString) method where subString might be more than just couple of chars (e.g. "This is the string to compare ") I have...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
8
by: gthorpe | last post by:
Hi, I have a question about string constants. I compile the following program: #include <stdio.h> #include <string.h> int main(void) { char str1 = "\007";
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.