473,763 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compare string

12 New Member
how to compare string in file i mean compare that string content digit or alphabet,and 1 question more can we count that line if first line variable = 1,if read second line variable = 2 and so on thanks
e.g

i have file with name data.txt with file like this

123456




abcdef
456897
asdffg


789654

gfdsah


the question how to compare that file and i now that string with content alphabet or number
and i want make make new file data2.txt from data.txt like this


123456 456897 789654 123456 abcdef 123456 asdffg gfdsah
Nov 6 '08 #1
4 3021
bvdet
2,851 Recognized Expert Moderator Specialist
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> line1 = '12345648737276488'
  2. >>> line2 = 'abcdef'
  3. >>> import string
  4. >>> numbers = set('1234567890')
  5. >>> alpha = set(string.ascii_letters)
  6. >>> set(line1).issubset(numbers)
  7. True
  8. >>> set(line2).issubset(alpha)
  9. True
  10. >>> set(line2).issubset(numbers)
  11. False
  12. >>> 
Nov 6 '08 #2
ndoe
12 New Member
hmmm,not like that,i mean how to write to file and we read that string from file to thanks for your help
Nov 8 '08 #3
bvdet
2,851 Recognized Expert Moderator Specialist
By what criteria are you reordering the data to write to another file?
Nov 8 '08 #4
nishi2rock
3 New Member
If your problem is about reading from and into files...

FileObj = open(Filename,m ode) eg:f = open("tmp.txt", "w")

read and readlines can be used to read data from file
eg: FileData = f.read() reads all the data of file into FileData

write and writelines can be used to write

coming to your string manipulations

someString = 'A string'

someString.isal pha() = True
someString.isal num() = True
someString.isdi git() = Flase

someString = '123456'

someString.isal pha() = False
someString.isal num() = True
someString.isdi git() = True

may be if you explain your sorting criteria it would be more explanatory
Nov 8 '08 #5

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

Similar topics

3
3195
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 entered the same string, different strings. The string is loaded from the results from a dataset. The other string is loaded from a textbox. Could someone please help me in this situation?
19
9519
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!
0
7771
by: William Stacey [MVP] | last post by:
Trying to figure out Dictionary<> and using CaseInsensitive Comparer<> like I did with normal Hashtable. The Hashtable can take a case insenstive Comparer and a Case insensitive HashCode provider. It seems the HashCode provider is lost or not needed in the Generic Dictionary anymore so wondering if this is how you do the same: Dictionary<string, Node> nodes = new Dictionary<string, Node>( new StringCompInsensitive() ); ....
4
7588
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
2
2488
by: Locia | last post by:
How can I compare "if argument"? example: if (leftExpression==RightExpression) After parsing I know the type of RightExpression. I suppone that if RightExpression is wrap into " " is a String. else I check if RightExpression is a int. else In final case, I check that RightExpression is a name of object
6
2129
by: Maileen | last post by:
Hi, I have the following code : Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String, ByVal EdPeriod As String, ByVal TaskType As String) As Integer Dim strtest As String Dim i, j As Integer i = strtest.Compare(EvDt,StPeriod) Select Case (TaskType) Case "Old"
4
6662
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
2
2107
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 "dir1\c.txt" But I would like them to be sorted as followed
1
2487
by: Lambda | last post by:
I defined a class: class inverted_index { private: std::map<std::string, std::vector<size_t index; public: std::vector<size_tintersect(const std::vector<std::string>&); };
11
2338
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 before the other. In a book I read they had used the second one but I prefer the first one because it it clearer.
0
9383
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
10140
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9935
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
8821
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...
1
7364
isladogs
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...
0
5268
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3916
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
3
2790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.