473,725 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8424
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.StartsWi th("-") will return true.
"ga********@myw ay.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.StartsWi th("-") = false))
{
Console.WriteLi ne(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(!StartsWi th("-")) 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********@myw ay.com> a écrit dans le message de news:
11************* *********@y43g2 00...legr oups.com...
line = sr.ReadLine();
while ((line.StartsWi th("-") = false))
{
Console.WriteLi ne(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
12625
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 character 2 and replace it with a different character.... etc.... until completing the string? thanks....
8
4062
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 problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
10
2861
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 someone let me know if the method I've used below is efficient or if there is a better way to do it, as these will be rather large strings I'm searching in. Thanks Public Shared Function CountDelimiter(ByVal strInput As String, ByVal...
11
1781
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 command or syntax to start at a certain character number (which I have) and then read until the first blank line then put it into another variable After that I want to do the same thing, kind of, and put the parts after the “=” sign into separate...
3
26226
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
2571
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 noticed that it executes quite slowly. Is there a way to do this faster? tx
35
75214
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
3104
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
10218
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
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.