473,666 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i compare two string and get the difference?

i have two strings from xml file

str1 = 800.7415_801.10 1_8.115_216.12
str2 = 800.7415_801.10 1_8.115_216.12_ 217.570

the first stream represent a xml file 800.7415_801.10 1_8.115_261.12. xml
which hold some value that can only be look up after i compare both string
so i can find where to look up the value of object type 217 and the instance
number 570

if i use string.compare i get -1 which mean str2 is greater than str1...but
i have no idea on what to do next. how do i compare both string and base on
the difference to get the 217 and 570
Jun 19 '06 #1
3 4931
Hi,

Just wondering if str2 will always contain str1? If this is the case
then you can do the following:

dim tempString() as string
'Check if str1 is part of str2, if yes, instr returns a positive
value
If InStr(str2, str1) > 0 Then
'str1 is part of str2, we will use the mid and split
methods to extract then
'needed characters.
'In your senario the mid method will return "217.570"
'After using the split method, you will have tempString(0)
= "217" and
' tempString(1) = "570"
tempString = Split(Mid(str2, Len(str1) + 1), ".")
End If
I hope that help you,

Cheers,
Ahmed
dotnetnoob wrote:
i have two strings from xml file

str1 = 800.7415_801.10 1_8.115_216.12
str2 = 800.7415_801.10 1_8.115_216.12_ 217.570

the first stream represent a xml file 800.7415_801.10 1_8.115_261.12. xml
which hold some value that can only be look up after i compare both string
so i can find where to look up the value of object type 217 and the instance
number 570

if i use string.compare i get -1 which mean str2 is greater than str1...but
i have no idea on what to do next. how do i compare both string and base on
the difference to get the 217 and 570


Jun 19 '06 #2
Hello dotnetnoob,

Well, I would start by removing the parts that are the same...
Dim tStringOne As String = 800.7415_801.10 1_8.115_216.12
Dim tStringTwo as String = 800.7415_801.10 1_8.115_216.12_ 217.570
Dim tResult As String = tStringTwo.Repl ace(tStringOne, String.Empty).T rim

This will make tResult = "_217.570". .. You should be able to take it from
there.

-Boo
i have two strings from xml file

str1 = 800.7415_801.10 1_8.115_216.12
str2 = 800.7415_801.10 1_8.115_216.12_ 217.570
the first stream represent a xml file
800.7415_801.10 1_8.115_261.12. xml which hold some value that can only
be look up after i compare both string so i can find where to look up
the value of object type 217 and the instance number 570

if i use string.compare i get -1 which mean str2 is greater than
str1...but i have no idea on what to do next. how do i compare both
string and base on the difference to get the 217 and 570

Jun 19 '06 #3
hi, thank you both. it seem like it is what i need.

str1 basically represent a xml file name and str2 hold where the file is and
the object type and instance number of this object.

"Ahmed" wrote:
Hi,

Just wondering if str2 will always contain str1? If this is the case
then you can do the following:

dim tempString() as string
'Check if str1 is part of str2, if yes, instr returns a positive
value
If InStr(str2, str1) > 0 Then
'str1 is part of str2, we will use the mid and split
methods to extract then
'needed characters.
'In your senario the mid method will return "217.570"
'After using the split method, you will have tempString(0)
= "217" and
' tempString(1) = "570"
tempString = Split(Mid(str2, Len(str1) + 1), ".")
End If
I hope that help you,

Cheers,
Ahmed
dotnetnoob wrote:
i have two strings from xml file

str1 = 800.7415_801.10 1_8.115_216.12
str2 = 800.7415_801.10 1_8.115_216.12_ 217.570

the first stream represent a xml file 800.7415_801.10 1_8.115_261.12. xml
which hold some value that can only be look up after i compare both string
so i can find where to look up the value of object type 217 and the instance
number 570

if i use string.compare i get -1 which mean str2 is greater than str1...but
i have no idea on what to do next. how do i compare both string and base on
the difference to get the 217 and 570


Jun 20 '06 #4

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

Similar topics

30
3437
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then I've also heard there are lots of weird ways to do some things kinda like Perl which is bad for me. Any other ideas?
3
5803
by: jyoti | last post by:
Hi there, I am trying to compare two strings and get the differenc in vbscript. Example: Str1="This is a test text" Str2="This is a fine test text but a little long" I like to compare str1 with str2 and get the difference. Above example the difference will be "fine" and "but a little long" How do I do that? A sample code would be apprciable.
8
62646
by: Sharon | last post by:
hi, I want to compare character, if the string contains character "-" then it will print Hello on the screen however, neither method (1) nor method (2) work in the code below: so what the correct code should be? thanks! #include <stdio.h> #include <stdlib.h> int main()
19
9506
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 have tried to print out by debug.writeline(). But the "==" operator results false, and string.Compare() results true. Somebody helps me!
4
28024
by: Sasidhar Parvatham | last post by:
Hi All, How do I compare two strings and get all the positions where there is a difference between them? Thanks, Sasidhar
11
17787
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is greater number than second 20 digit number ,then it should return.
4
6658
by: Lamis | last post by:
Hi, what is the best way to compare 2 haschtables contatining objects. the objects has 2 property, name & value. I need to print out the differences -- LZ
3
5401
by: artev | last post by:
in the default sort which is the compare function used? alphabetical ordination is so:arry.sort(); but which is the default function used? is there a good link wich example for alphabetical order and also for multiarray order? (previous post)
6
2634
by: Muhs | last post by:
Hi !! i want to compare two strings and return the difference For example, i have two strings, string str1="then"; string str2="than"; it compared the two strings and returns 1, as only one character is different (a and e). Is there a function in c# that can do this??
0
8356
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,...
0
8781
jinu1996
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...
1
8550
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,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
agi2029
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...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.