473,394 Members | 1,821 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.

string between two delimiters....

I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?

Thanks in Advance for any help
Oct 9 '08 #1
4 14093
On Oct 9, 9:56*am, kw_uh97 <kwu...@discussions.microsoft.comwrote:
I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?
This is a really simple thing to do, apparently you are a real newbie
to programming.

If all you need to do is strip off the leading and trailing single
quote characters, and assuming there will not be any embedded single
quote characters anywhere inside of the leading and trailing single
quotes that would need to remain, all you would do is:

string myString = "'mystring'";

myString = myString.Replace("'", "");
Oct 9 '08 #2

"kw_uh97" wrote:
I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?

Thanks in Advance for any help
To extract mystring from the 'mystring' in the lines above you typically use
RegEx expressions.

using System.Text.RegularExpression;
....
Regex expression = new Regex("'[^']*'");
Match match = expression.Match("some string with 'apples' and 'bananas'");
string result = match.Value.Trim(new char[] { '\'' });

The above code match will contain 'apples', which you can strip the ' from
in numerous ways. Calling match.NextMatch() will give you 'orange' etc.

You can also do it without RegEx

string s = "some string with 'apples' and 'bananas'";
int start = s.IndexOf('\'') + 1;
int end = s.IndexOf('\'', start);
string result = s.Substring(start, end - start);

But this method may cause exceptions if you are missing a '

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 9 '08 #3
Sorry about that. I am indeed a newbie to programming and I started the
preface my question with an apology letting everyone know that my brain is
not functioning properly due to that I am under the weather. The effects of
the benadryle and cough medicine have me drowsy and sluggish. Sorry for my
laziness. :>)

"za***@construction-imaging.com" wrote:
On Oct 9, 9:56 am, kw_uh97 <kwu...@discussions.microsoft.comwrote:
I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?

This is a really simple thing to do, apparently you are a real newbie
to programming.

If all you need to do is strip off the leading and trailing single
quote characters, and assuming there will not be any embedded single
quote characters anywhere inside of the leading and trailing single
quotes that would need to remain, all you would do is:

string myString = "'mystring'";

myString = myString.Replace("'", "");
Oct 9 '08 #4
This was exactly what I was looking for because my string was containing text
before my delimiters and all I needed was what was between my delimiters.

Many Thanks.

"Morten Wennevik [C# MVP]" wrote:
>
"kw_uh97" wrote:
I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?

Thanks in Advance for any help

To extract mystring from the 'mystring' in the lines above you typically use
RegEx expressions.

using System.Text.RegularExpression;
...
Regex expression = new Regex("'[^']*'");
Match match = expression.Match("some string with 'apples' and 'bananas'");
string result = match.Value.Trim(new char[] { '\'' });

The above code match will contain 'apples', which you can strip the ' from
in numerous ways. Calling match.NextMatch() will give you 'orange' etc.

You can also do it without RegEx

string s = "some string with 'apples' and 'bananas'";
int start = s.IndexOf('\'') + 1;
int end = s.IndexOf('\'', start);
string result = s.Substring(start, end - start);

But this method may cause exceptions if you are missing a '

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 9 '08 #5

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

Similar topics

12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
10
by: John | last post by:
Ok, I posted in here a few days ago about a problem with apostrophes in text fields and I tried a few of the suggestions and now I'm in so deep I looking at scraping the whole thing because now I...
4
by: Ernesto | last post by:
I'm trying to use a $ delimeter, but it doesn't seem to work. Here is the code: launchWithoutConsole("devcon.exe",d'$enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000"$) I want to send...
7
by: tommaso.gastaldi | last post by:
I have a file containing some commands in free format. Each command is terminated with ";". The ";" can also be found within the command but, only enclosed within delimiters (' or ""). Example: ...
16
by: Amit Gupta | last post by:
Hi - I get a seg-fault when I compile and run this simple program. (seg-fault in first call to strtok). Any clues? My gcc is "gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)" #include...
8
by: Mugunth | last post by:
I'm writing a search engine crawler for indexing local files in C# My dataset is about 38000 XML files and as of now, I've successfully parsed the file, and tokenized it. But, it's surprising to...
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
5
by: gpaps87 | last post by:
hi, i wanted to know whether we can use strtok command to mark delimiters as tokens as well.In Java,we have a command: StringTokennizer(String str, String delimiters, boolean delimAsToken) ...
2
by: ylj798 | last post by:
this string from web by the Regular Expression$B!$(B $B!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!]!](B href="#" onClick="ConvertURL2FG('Flashget://...
5
by: alex21 | last post by:
I am trying to write a function for determining the data type of columns in a delimited file. However my function is not detecting a newline and exiting the loop after the end of the first line. ...
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: 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?
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
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
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...

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.