Hello,
I have one question about string.I am trying to make an function to
analyze line of some text, this is my example: "HELLO;HELLO2:W ORLD:",
if that function in this text find ";" and ":" ( in this example will
find both)
e.g that function must return this:
"HELLO;\nHELLO2 :\n\t\t\t\t\t\t \tWORLD:"
Regards,
Vedran 9 1177
On Jul 27, 8:23 am, vedrandeko...@v-programs.com wrote:
Hello,
I have one question about string.I am trying to make an function to
analyze line of some text, this is my example: "HELLO;HELLO2:W ORLD:",
if that function in this text find ";" and ":" ( in this example will
find both)
e.g that function must return this:
"HELLO;\nHELLO2 :\n\t\t\t\t\t\t \tWORLD:"
Regards,
Vedran
You can use split twice
print text.split( ":" )
and then split the returned list items on ";".
You could also use text.find( ":" ), but that would be pretty much the
same thing only harder. Also, you can step through the string one
character at a time and compare each character. Finally, you can use
an re, (regular expression), but if you are still learning how to
parse strings, I don't think you want to get into re's. ve***********@v-programs.com wrote:
I have one question about string.I am trying to make an function to
analyze line of some text, this is my example: "HELLO;HELLO2:W ORLD:",
if that function in this text find ";" and ":" ( in this example will
find both)
e.g that function must return this:
"HELLO;\nHELLO2 :\n\t\t\t\t\t\t \tWORLD:"
If I understand you correctly you want to replace ";" by ";\n" and ":"
by ":\n\t\t\t\t\t\ t\t".
Well guess what? The replace() method does just this. Have a read:
<URL:http://docs.python.org/lib/string-methods.html>
/W
On 27 srp, 19:29, Wildemar Wildenburger <wilde...@freak mail.dewrote:
vedrandeko...@v-programs.com wrote:
I have one question about string.I am trying to make an function to
analyze line of some text, this is my example: "HELLO;HELLO2:W ORLD:",
if that function in this text find ";" and ":" ( in this example will
find both)
e.g that function must return this:
"HELLO;\nHELLO2 :\n\t\t\t\t\t\t \tWORLD:"
If I understand you correctly you want to replace ";" by ";\n" and ":"
by ":\n\t\t\t\t\t\ t\t".
Well guess what? The replace() method does just this. Have a read:
<URL:http://docs.python.org/lib/string-methods.html>
/W
Hello,
No,that's not what I need...
When this function detect ";" or ":" ,it must append character "\n" or
"\n\t" ahead ":" or ";" another e.g
1) text="Hello world;Hello:Hel lo2"
2) When function detect ";" or ":" it must append character "\n" or "\n
\t" ahead ":" or ";", so that must look like this:
NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
Regards,
Vedran ve***********@v-programs.com wrote:
>If I understand you correctly you want to replace ";" by ";\n" and ":" by ":\n\t\t\t\t\t\ t\t". Well guess what? The replace() method does just this. Have a read: <URL:http://docs.python.org/lib/string-methods.html>
No,that's not what I need...
When this function detect ";" or ":" ,it must append character "\n" or
"\n\t" ahead ":" or ";" another e.g
1) text="Hello world;Hello:Hel lo2"
2) When function detect ";" or ":" it must append character "\n" or "\n
\t" ahead ":" or ";", so that must look like this:
NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
Isn't that what I said?
Please note that appending "\n" to ";" is the very same thing as
replacing ";" with ";\n".
Also note that the your description of the desired behavior does not
match your example. You say "append "\n\t" after ":"", but thats not
what happens in your example. There you append "\n\t\t\n\n\n\n \n\n"
instead of "\n\t". That is confusing to me. Can you explain?
/W
On Jul 27, 11:26 am, Wildemar Wildenburger <wilde...@freak mail.de>
wrote:
vedrandeko...@v-programs.com wrote:
If I understand you correctly you want to replace ";" by ";\n" and ":"
by ":\n\t\t\t\t\t\ t\t".
Well guess what? The replace() method does just this. Have a read:
<URL:http://docs.python.org/lib/string-methods.html>
No,that's not what I need...
When this function detect ";" or ":" ,it must append character "\n" or
"\n\t" ahead ":" or ";" another e.g
1) text="Hello world;Hello:Hel lo2"
2) When function detect ";" or ":" it must append character "\n" or "\n
\t" ahead ":" or ";", so that must look like this:
NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
Isn't that what I said?
Please note that appending "\n" to ";" is the very same thing as
replacing ";" with ";\n".
Also note that the your description of the desired behavior does not
match your example. You say "append "\n\t" after ":"", but thats not
what happens in your example. There you append "\n\t\t\n\n\n\n \n\n"
instead of "\n\t". That is confusing to me. Can you explain?
/W
Confusing to me also. I read this as replace the first ";" with ";/
n", replace the first ":" with "\n\t\t\t\t\t\t \t", and on from there
with different requirements. If that is the case then you have to
locate the first, second, etc. and add/replace with the appropriate
code. String.find and split would have to be used instead of a
string.replace if you want to make different changes depending on if
it is the first, second..., occurrence.
vedrandeko...@v-programs.com wrote:
NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
If you are doing all of this to format the output into columns,
Python's print() or write() will do this, and is easier as well. Some
more info on what you want to do will clear things up.
On 28 srp, 07:05, Zentrader <zentrad...@gma il.comwrote:
vedrandeko...@v-programs.com wrote:
NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
If you are doing all of this to format the output into columns,
Python's print() or write() will do this, and is easier as well. Some
more info on what you want to do will clear things up.
Hi,
That is confusing me too, so now I will try explain it more.This is
text before "translatio n":
Let me explain you with python code. I want to this "function" act
code indentation
>>Short_Text="n =90; if n==90:print 'ok'"
Then now I must write that function for detect ";" and ":", and if
that function detect ";" then it appends "\n" before ";" but
if detect ":" then it appends "\n\t\t\t\t\t\t \t\t"
>>Short_text_af ter_translation ="n=90;\nif n==90:\n\t\t\t\ t\t\t\t\tprint 'ok"
....And now when we run this code with exec this must look like:
n=90;
if n==90:
print 'ok'
I think this will be enough for help.
Regards,
Vedran ve***********@v-programs.com wrote:
On 28 srp, 07:05, Zentrader <zentrad...@gma il.comwrote:
>>>vedrandeko.. .@v-programs.com wrote: NEW TEXT : "Hello world;\nHello:\ n\t\t\n\n\n\n\n \nHello2"
If you are doing all of this to format the output into columns, Python's print() or write() will do this, and is easier as well. Some more info on what you want to do will clear things up.
Hi,
That is confusing me too, so now I will try explain it more.This is
text before "translatio n":
Let me explain you with python code. I want to this "function" act
code indentation
>>>Short_Text=" n=90; if n==90:print 'ok'"
Then now I must write that function for detect ";" and ":", and if
that function detect ";" then it appends "\n" before ";" but
if detect ":" then it appends "\n\t\t\t\t\t\t \t\t"
>>>Short_text_a fter_translatio n="n=90;\nif n==90:\n\t\t\t\ t\t\t\t\tprint 'ok"
...And now when we run this code with exec this must look like:
n=90;
if n==90:
print 'ok'
I think this will be enough for help.
OK, but you don't want that many tab characters if you can the code to
look like you show it. It's not, anyway, a good idea to use tabs to
indent code.
I suspect what you need is to split the code on semicolons first, then
re-form lines with colons in them. Some simple code to do this would
look *something* like what follows. This will handle a little more than
you wanted.
>>Short_Text="n =90; if n==90:print 'ok'" compound_line s = Short_Text.spli t(";") for line in compound_lines:
.... line = line.replace(": ", ":\n ")
.... print line
....
n=90
if n==90:
print 'ok'
>>>
Note there are issues here that I haven't addressed. The first is that
leading spaces on the second statement need to be removed, and the
second is that this only works at the outermost level of indentation.
For example, if you want to end up translating function definitions with
if statements inside them correctly you will need to handle multiple
levels of indentation. There are other problems, like semicolons and
colons inside string constants should be ignored, but the only way to
get over those will be to parse the program text according to some
grammar rather than using ad-hoc methods such as the above.
I hope I have finally been of some assistance ... please reply via the
newsgroup, not in personal email.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
>>Short_Text="n =90; if n==90:print 'ok'"
>>compound_line s = Short_Text.spli t(";")
>>for line in compound_lines:
... line = line.replace(": ", ":\n ")
... print line
...
n=90
if n==90:
print 'ok'
A variation of this will work if the input file isn't too
complicated. I found this link with a Google of "c to python". This
will give you an idea of how difficult it can be if you take into
account every possibility when converting. You might check the web
first, since someone has probably already done what you want. Good
luck. http://www.catb.org/~esr/ctopy/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott |
last post by:
The following is the XML I have to work with. Below is the question
<Table0>
<CaseID>102114</CaseID>
<CaseNumber>1</CaseNumber>
<DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>
<OnCallPerson />
<CallType>Exposure</CallType>
<ExposureReason>General</ExposureReason>
<OtherExposureReason>Unintentional</OtherExposureReason>
<ClientName>Test Client</ClientName>
|
by: Raskolnikow |
last post by:
Hi!
I have a very simple problem with itoa() or the localtime(...).
Sorry, if it is too simple, I don't have a proper example.
Please have a look at the comments.
struct tm *systime;
time_t currentTime;
char day;
char month;
|
by: Alan |
last post by:
hi all,
I want to define a constant length string, say 4
then in a function at some time, I want to set the string to a constant
value, say a
below is my code but it fails
what is the correct code?
many thx!
|
by: Brian Henry |
last post by:
Hello,
I was tring to learn socket's (being i never used them before) and have a
simple question. I want to create a listner that will get any data recieved
and print it out. I've been able to get it to recieve only one line of data,
but the next one i send to it wont be printed like the 1st one. I had a
listner running in a thread, does anyone have a simple listner code example
that would show how to have a tcplistner thread running...
|
by: dba_222 |
last post by:
Dear Experts,
Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.
In Sql server, how do I simply change a character into a number??????
In Oracle, it is:
| |
by: Paulo da Silva |
last post by:
Hi!
I was told in this NG that string is obsolet. I should use
str methods.
So, how do I join a list of strings delimited by a given
char, let's say ','?
Old way:
|
by: SM |
last post by:
Hello,
I have a simple question, but can't find the answer.
I have a string that contains a path to a file
I want to add another string to the end of that string
So, if i have :
path = document/disco/album/hello.doc
i want it to become :
document/disco/album/hello_large.xls
|
by: galiorenye |
last post by:
Hi,
Given this code:
A** ppA = new A*;
A *pA = NULL;
for(int i = 0; i < 10; ++i)
{
pA = ppA;
//do something with pA
|
by: Phillip Taylor |
last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Services.WebService(Namespace:="http://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
|
by: Chris M. Thomasson |
last post by:
I use the following technique in all of my C++ projects; here is the example
code with error checking omitted for brevity:
_________________________________________________________________
/* Simple Thread Object
______________________________________________________________*/
#include <pthread.h>
extern "C" void* thread_entry(void*);
|
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,...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |