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

compare string

12
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 2998
bvdet
2,851 Expert Mod 2GB
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
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 Expert Mod 2GB
By what criteria are you reordering the data to write to another file?
Nov 8 '08 #4
If your problem is about reading from and into files...

FileObj = open(Filename,mode) 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.isalpha() = True
someString.isalnum() = True
someString.isdigit() = Flase

someString = '123456'

someString.isalpha() = False
someString.isalnum() = True
someString.isdigit() = 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
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...
0
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....
4
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
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...
6
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...
4
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
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...
1
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
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
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,...
0
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...
0
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...

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.