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

Check the first 2 characters of string

Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards

Jul 30 '08 #1
6 25053
On Jul 30, 12:22 pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards
strSurname.StartsWith("%")
Jul 30 '08 #2
On Jul 30, 12:22 pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards
strSurname.StartsWith("%%")
Jul 30 '08 #3
On Jul 30, 8:22 pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards
You can get first two chars of a string with substring method like
below:

Dim foo As String = "foo"
'outputs "fo"
foo = foo.Substring(0, 2)

However, i'm not sure why you're looking for first 2 chars of the
string for determining if describes a percentage.

For example, you can use StartsWith("%") function depending on your
implementation of your application.

Thanks,

Onur


Jul 30 '08 #4
Please always check the documentation before posting. For example try :
http://msdn.microsoft.com/en-us/libr...tartswith.aspx.
Intellisense should have also shown what you could do with a string
(http://msdn.microsoft.com/en-us/libr...b(vs.71).aspx)...

As you seems to be a beginner you may want also to read the language
specification once (not sure which one you are suing as you post what seems
an erroneous c# line in a vb group).

Finally in case you would have some sort of error ( do you miss the final ;
character in your code ?) post about the error you got rather than asking
such a general and basic question...

--
Patrice

"axapta" <ja********@gmail.coma écrit dans le message de groupe de
discussion : D0**********************************@microsoft.com...
Hi Group,
How can I check that the first 2 characters of a string are the percent
(%) sign?
string name = strSurname

Regards

Jul 30 '08 #5
On Wed, 30 Jul 2008 18:22:09 +0100, "axapta" <ja********@gmail.com>
wrote:
>Hi Group,
How can I check that the first 2 characters of a string are the percent (%)
sign?
string name = strSurname

Regards
If Mid(mystring, 1, 2) = "%%" Then
'Do whatever
End If
Jul 30 '08 #6
"Kevinp" <kmahoney@nospam_fireacademy.orgschrieb:
>>How can I check that the first 2 characters of a string are the percent
(%)
sign?
string name = strSurname

Regards

If Mid(mystring, 1, 2) = "%%" Then
'Do whatever
End If
VB6-style: 'If Left(MyString, 2) = "%%" Then...'. You could also use the
'Like' string comparison operator with an appropriate pattern. However, I
doubt that these solutions are better than 'String.StartsWith'.

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

Jul 30 '08 #7

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

Similar topics

9
by: Henke | last post by:
Hi! Is there a simple way to check if a string entered in a text box is a valid integer? Thanks in advance! /Henke
4
by: Hamed | last post by:
Hello How can I check if a string is empty? Thanks
7
by: zjut | last post by:
I need to implement the method : round(String name, int index) The given string maybe the every type of float type, ( the msdn given the regax is that : integral-digits]exponential-digits]) ...
1
by: Lala | last post by:
Hi, I need to check if a string contains unicode characters, and generate an alert if it does. (I do not want to parse the string to unicode). Anyone who knows how to do this? Thanks! :D
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
3
by: kathy | last post by:
I want to know what is the easy way to check if a string is a number or not? the number can be int, float, double, scientific,... what is the easy way for only interger?
6
by: garyusenet | last post by:
Hello, Can someone tell me how to check if a string variable starts with a dash. ' - ' Thanks, Gary.
31
by: noagbodjivictor | last post by:
How to check if a string is empty in python? if(s == "") ??
8
by: danon | last post by:
Hi evrey one needing you're hlp please can any one tel me how to programme a first characters uppercase in textbox thank you
21
by: Yoni Hasid | last post by:
Hello, I am trying to match tables into a query based on 5 first characters in one field. I used expression: =left(), 5) however it does not return matched entries as I needed. Basically, I need to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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: 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...

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.