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

Compare two strings and combine into a string.

Hi,

I have two strings as below:

Expand|Select|Wrap|Line Numbers
  1. string a = "A, 0001; B, 0002; C, 0003;";
  2. string b = "0001, From, FlowA; 0002, To, FlowB; 0003, From, FlowC; 0003, To, FlowD;";
  3.  
I would like to produce a new string c with the output:

A, From, FlowA; B, To, FlowB; C, From, FlowC; C, To, FlowD;

Is that anyway for me to do it?
Thank.
Mar 19 '10 #1

✓ answered by tlhintoq

You can use String.Split to split each source string into string arrays
Then merge together whatever parts you want.

5 2299
tlhintoq
3,525 Expert 2GB
You can use String.Split to split each source string into string arrays
Then merge together whatever parts you want.
Mar 19 '10 #2
jkmyoung
2,057 Expert 2GB
Looks like after you use String.Split twice, just use String.Replace with the items of the string arrays as arguments.
Mar 19 '10 #3
You would have to apply a combination of string.split and string.replace to accomplish that.
Mar 22 '10 #4
Hi harrisunderwork,

Thank for your answer. Based on your answer, i should apply the string.replace in combination of string. However, string.replace is used to replace certain word in a sentences. In my case, i would like to combine this two string and at the same the similar word is needed to eliminate. Does string.replace can make it?

Now, i'am using the foreach and array method together in order to get the output. Thank.
Mar 22 '10 #5
jkmyoung
2,057 Expert 2GB
Yes, you would do something like:

b = b.Replace("A", "0001");
except "A" and "0001" would be variables which are set when you tokenize the string.
Mar 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: J.W. | last post by:
How do I compare strings in javascript? The "==" double equals or "!=" doesn't seem to work in this case. I'm sure string comparison has been explained before but searching Google didn't find...
9
by: Craig | last post by:
Hello friends at comp.lang.c, I'm trying to combine 2 strings with a newline character at the end to write to a file. When I view the file, the messages run together and some of the str string...
3
by: Drew | last post by:
Hello - I am a converted VB programmer. What I am trying to do it compare two strings in an if statement. The problem is that when I use string.compare it always returns a negative 1. I have...
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
14
by: Samuel R. Neff | last post by:
Why would you cast two strings to objects to compare them? I saw code in an MS sample on MSDN and don't get it. if ( (object)name == (object)attr.name ) { both "name" and "attr.name" are...
5
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
4
by: Jim Langston | last post by:
Is there any builtin lowercase std::string compare? Right now I'm doing this: if ( _stricmp( AmmoTypeText.c_str(), "GunBullet" ) == 0 ) AmmoType = Item_Ammo_GunBullet; Is there anything the...
3
by: Twinkle | last post by:
HI there i want to compare between two strings char by char.every strings having a word document.first string name is strFileName and second string name is strFilename1. i want to compare...
2
by: Peter Proost | last post by:
Hi group, I want to compare path strings in order to sort them, assuming I have got: "a.txt" "dir1\c.txt" "e.txt" "dir1\d.txt" When I compare them using "e.text" would be greater than...
11
by: Tony | last post by:
Hello! Below I have two different ways to test if the instance tb.Text contains the string "Programmer" So which one to use is it just a matter of taste ? Or could it be some advantage to one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.