473,407 Members | 2,315 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,407 software developers and data experts.

How to change part of a variable (string)?

I have a variable "fileName" = ****.pdb, where the *s are capitalised letters. After a method uses this variable as an argument, I need to change the extension part to .ent without changing the first part. For some reason, none of the str.replace methods seem to work.
Oct 27 '10 #1
3 4685
dwblas
626 Expert 512MB
none of the str.replace methods seem to work.
Yes they do. Post what you have tried and someone will tell you where you went wrong.
Oct 27 '10 #2
Glenton
391 Expert 256MB
If you know it's always that format you can just use:
Expand|Select|Wrap|Line Numbers
  1. newstring=fileName[:-3]+"ent"
Oct 28 '10 #3
bvdet
2,851 Expert Mod 2GB
Keep in mind strings are immutable. You must reassign the string returned by the replace method to an identifier.
Expand|Select|Wrap|Line Numbers
  1. >>> s = "somestring.txt"
  2. >>> s.replace("txt", "xyz")
  3. 'somestring.xyz'
  4. >>> s
  5. 'somestring.txt'
  6. >>> news = s.replace("txt", "xyz")
  7. >>> news
  8. 'somestring.xyz'
Oct 28 '10 #4

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

Similar topics

1
by: Cyper Hunter | last post by:
Hi: Do you know how to change the url string of URL object? For example, I have an URL object declared as: URL myurl = new URL("http://www.cnn.com"); How to change the url string of myurl...
2
by: praba kar | last post by:
Dear All, In Php strtotime() will change a date string into timestamp. I want to know which python function will change a date string into timestamp. Date string format is below
2
by: Ben | last post by:
Hi, Does any body know how to change sever variable value on runtime ? Thanks
0
by: krishnacins | last post by:
Dear Sir, i want know how to change char or string into unsigned short. Actualy i want to store a string into 2 bytes data type variable of pointer. Like unsigned short s={'H','e','l','l','o',0};...
3
by: Hari | last post by:
Hi all, I need to get a part of string which follows a pattern 'addr=' For example: a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)"
2
by: paolol | last post by:
Hi, I have a dataset with few tableAdapter and I wish to change the connection string by user imput, the only way I found to do that is using each tableadapter, but in this way I have change one...
0
by: Alias | last post by:
Hi - I have a site that runs on a development and production server. I'd like to programmatically change the connection string the provider uses in the web.config file and have the provider use...
2
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
4
by: Ron Garret | last post by:
Is there a way to change the default string encoding used by the string.encode() method? My default environment is utf-8 but I need it to be latin-1 to avoid errors like this: Traceback (most...
2
by: veer | last post by:
i have a string c:\var\newdata\123456\123456_1.mdb i want the first part of string from right side l,e 123456_1.mdb how is it possible please send me some code
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: 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?
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
marktang
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,...
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
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,...
0
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...

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.