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.

Manipulate / Strip String

G
Hello,

Does anyone have any code handy which will take a certain part of a string
and save it as an independant string?

For example:

"Thank you for visiting our web site. You were sent here by Michael Smith
from Aberdeen who thought you would find this page interesting."

If I wanted to save the part "Michael Smith from Aberdeen" , how would I go
about loosing the bits on the left and right? I think in classic ASP it was
the String replace function.

Any help appreciated.

Regards,

Gary.

Feb 28 '07 #1
4 5124
Try SomeString.Replace() or SomeString.Substring(), depending on what
exactly you want to do (e.g. can you guarantee the substring you want will
start at some specific index from the start of the string and end at some
specific index from the end of the string).

It's all on MSDN. Try:

http://msdn2.microsoft.com/en-us/lib...ds(VS.80).aspx
Peter
"G" <g@nospam.comwrote in message
news:BB**********************************@microsof t.com...
Hello,

Does anyone have any code handy which will take a certain part of a string
and save it as an independant string?

For example:

"Thank you for visiting our web site. You were sent here by Michael Smith
from Aberdeen who thought you would find this page interesting."

If I wanted to save the part "Michael Smith from Aberdeen" , how would I
go about loosing the bits on the left and right? I think in classic ASP
it was the String replace function.

Any help appreciated.

Regards,

Gary.

Feb 28 '07 #2
G <g@nospam.comwrote:
Does anyone have any code handy which will take a certain part of a string
and save it as an independant string?

For example:

"Thank you for visiting our web site. You were sent here by Michael Smith
from Aberdeen who thought you would find this page interesting."

If I wanted to save the part "Michael Smith from Aberdeen" , how would I go
about loosing the bits on the left and right? I think in classic ASP it was
the String replace function.
String.Substring is almost certainly what you want here - but you'll
need to be able to work out exactly which bit of the string you're
interested in.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 28 '07 #3
G wrote:
Hello,

Does anyone have any code handy which will take a certain part of a
string and save it as an independant string?

For example:

"Thank you for visiting our web site. You were sent here by Michael
Smith from Aberdeen who thought you would find this page interesting."

If I wanted to save the part "Michael Smith from Aberdeen" , how would I
go about loosing the bits on the left and right? I think in classic ASP
it was the String replace function.

Any help appreciated.

Regards,

Gary.
In the String class you have a lot of methods to manipulate strings.

This example will put together a string, then extract the referrer by
stripping off the first and last strings:

string referrer = "Michael Smith from Aberdeen";
string message1 = "Thank you for visiting our web site. You were sent
here by ";
string message2 = " who thought you would find this page interesting.";
string message = message1 + referrer + message2;

string extract = message.Substring(message1.Length, message.Length -
message1.Length - message2.Length);

--
Göran Andersson
_____
http://www.guffa.com
Feb 28 '07 #4
On Wed, 28 Feb 2007 10:17:57 -0000, G wrote:
Hello,

Does anyone have any code handy which will take a certain part of a string
and save it as an independant string?

For example:

"Thank you for visiting our web site. You were sent here by Michael Smith
from Aberdeen who thought you would find this page interesting."

If I wanted to save the part "Michael Smith from Aberdeen" , how would I go
about loosing the bits on the left and right? I think in classic ASP it was
the String replace function.

Any help appreciated.

Regards,

Gary.
Regular expressions are another approach, especially if there are subtle
patterns in your strings that would trip up good old string.Replace()
--
Bits.Bytes
http://bytes.thinkersroom.com
Feb 28 '07 #5

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

Similar topics

6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
6
by: Mark C | last post by:
All, Is there such a function that can strip all non alpha ( not between a-z) characters from a string? I have a function that I currently use that will strip one character at a time from a...
5
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or...
0
by: Brian Henry | last post by:
I thought this was useful, its a extender i just wrote for the new .NET menu strip and status strip to extend the menu items to add a status message so when a mouse rolls over the item it displays...
6
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious......
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
6
by: Christoph Zwerschke | last post by:
In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url Similarly for stripping...
4
by: Poppy | last post by:
I'm using versions 2.5.2 and 2.5.1 of python and have encountered a potential bug. Not sure if I'm misunderstanding the usage of the strip function but here's my example. var = "detail.xml"...
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...
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
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:
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
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.