Manipulate / Strip String

  • Thread starter Thread starter G
  • Start date Start date
G

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.
 
G said:
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.
 
G said:
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);
 
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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top