I have a string like
string myString="dog,c at,dog,tiger"
I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that? 5 1566
Use the InStr and Replace methods.
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"ad" <ad@wfes.tcc.ed u.tw> wrote in message
news:Os******** *****@TK2MSFTNG P15.phx.gbl... I have a string like
string myString="dog,c at,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that?
ad,
First, you need to create a hashtable (or dictionary, I'll use a
hashtable since I don't know if you have access to .NET 1.1).
// Create the hashtable. If you want case-insensitivity, then you have to
use
// an overload of the constructor that takes the appropriate
case-insensitive
// comparer.
Hashtable parts = new Hashtable()
// Cycle through the parts.
foreach (string part in myString.Split( new char[1]{','}))
{
// If the part exists in the hashtable, don't add it.
if (!parts.Contain sKey(part))
{
// Add the part.
parts.Add(part, true);
}
}
// Now cycle through the parts and re-create the string.
// The builder for the new string.
StringBuilder builder = new StringBuilder() ;
// Cycle through the keys.
foreach (string key in parts.Keys)
{
// Append to the string builder.
parts.AddFormat ("{0},", key);
}
// Remove the last comma.
if (parts.Count > 0) then
{
// Remove the last comma.
parts.Remove(bu ilder.Length - 1, 1);
}
// The string.
myString = builder.ToStrin g();
I didn't run this, so make sure you test it first.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"ad" <ad@wfes.tcc.ed u.tw> wrote in message
news:Os******** *****@TK2MSFTNG P15.phx.gbl... I have a string like
string myString="dog,c at,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that?
Hi,
Could you give me some code?
"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > ¼¶¼g©ó¶l¥ó·s»D: eS************* *@TK2MSFTNGP14. phx.gbl... Use the InStr and Replace methods.
<%= Clinton Gallagher METROmilwaukee (sm) "A Regional Information Service" NET csgallagher AT metromilwaukee. com URL http://metromilwaukee.com/ URL http://clintongallagher.metromilwaukee.com/
"ad" <ad@wfes.tcc.ed u.tw> wrote in message news:Os******** *****@TK2MSFTNG P15.phx.gbl...I have a string like
string myString="dog,c at,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that?
Thanks,
You do me a great favor!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> ¼¶¼g©ó¶l¥ó·s»D: %2************* **@TK2MSFTNGP15 .phx.gbl... ad,
First, you need to create a hashtable (or dictionary, I'll use a hashtable since I don't know if you have access to .NET 1.1).
// Create the hashtable. If you want case-insensitivity, then you have to use // an overload of the constructor that takes the appropriate case-insensitive // comparer. Hashtable parts = new Hashtable()
// Cycle through the parts. foreach (string part in myString.Split( new char[1]{','})) { // If the part exists in the hashtable, don't add it. if (!parts.Contain sKey(part)) { // Add the part. parts.Add(part, true); } }
// Now cycle through the parts and re-create the string. // The builder for the new string. StringBuilder builder = new StringBuilder() ;
// Cycle through the keys. foreach (string key in parts.Keys) { // Append to the string builder. parts.AddFormat ("{0},", key); }
// Remove the last comma. if (parts.Count > 0) then { // Remove the last comma. parts.Remove(bu ilder.Length - 1, 1); }
// The string. myString = builder.ToStrin g();
I didn't run this, so make sure you test it first.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"ad" <ad@wfes.tcc.ed u.tw> wrote in message news:Os******** *****@TK2MSFTNG P15.phx.gbl...I have a string like
string myString="dog,c at,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that?
That's a lot of code for what I presumed InStr and Replace methods could do
in a couple of lines of code.
Any comments about my sugesstion Nicholas?
<%= Clinton Gallagher
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** *******@TK2MSFT NGP15.phx.gbl.. . ad,
First, you need to create a hashtable (or dictionary, I'll use a hashtable since I don't know if you have access to .NET 1.1).
// Create the hashtable. If you want case-insensitivity, then you have to use // an overload of the constructor that takes the appropriate case-insensitive // comparer. Hashtable parts = new Hashtable()
// Cycle through the parts. foreach (string part in myString.Split( new char[1]{','})) { // If the part exists in the hashtable, don't add it. if (!parts.Contain sKey(part)) { // Add the part. parts.Add(part, true); } }
// Now cycle through the parts and re-create the string. // The builder for the new string. StringBuilder builder = new StringBuilder() ;
// Cycle through the keys. foreach (string key in parts.Keys) { // Append to the string builder. parts.AddFormat ("{0},", key); }
// Remove the last comma. if (parts.Count > 0) then { // Remove the last comma. parts.Remove(bu ilder.Length - 1, 1); }
// The string. myString = builder.ToStrin g();
I didn't run this, so make sure you test it first.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"ad" <ad@wfes.tcc.ed u.tw> wrote in message news:Os******** *****@TK2MSFTNG P15.phx.gbl...I have a string like
string myString="dog,c at,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,ti ger"
How can I do that?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Jorgensen |
last post by:
A while back, I started boning up on Software Engineering best practices and
learning about Agile programming. In the process, I've become much more
committed to removing duplication in code at a much finer level. As such,
it's very frustrating to be working in VBA which lacks inheritance, one of the
more powerful tools for eliminating duplication at the level I'm talking
about.
I've recently come up with a technique to emulate one...
|
by: Steve Jorgensen |
last post by:
A while back, I started boning up on Software Engineering best practices and
learning about Agile programming. In the process, I've become much more
committed to removing duplication in code at a much finer level. As such,
it's very frustrating to be working in VBA which lacks inheritance, one of the
more powerful tools for eliminating duplication at the level I'm talking
about.
I've recently come up with a technique to emulate one...
|
by: Pauke |
last post by:
I want to add a primary key to a table with some duplicates and I have to get rid of them first, keeping the first row from each duplication case.
Say I found a case of duplication where there are 5 rows with t1.id=3. Other columns may be identical or not (I cannot count on it).
I'm looking for something like
delete top (5) * from t1 where not exists (select top (1) * from t1 where t1.id=3)
I'm looking for a solution that will not...
|
by: scott.tang |
last post by:
I'm experiencing a very strange problem. My application is MS Access
front-end and MS SQL server back-end database. I have a SQL statement
that deletes records from a table after an export process. The
problem is occasionally when the delete statement is executed, these
records no longer display on List Box (not even in the MS Access link
table). But when close and reopen the form, those records reappear.
It almost like MS SQL server...
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |