By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

Removing part of string

P: n/a
Hi,
I am parsing an xml file ,and one part of structure looks
something like this:

- <COMPARAM id="_338" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_AX </SHORTNAME>
<LONGNAME>Timeout N_As/N_Ar</LONGNAME>
<DESCRIPTION>Time from transmit request until a CAN frame transmit
confirmation is received.</DESCRIPTION>
</COMPARAM>

In my code i am extracting the data within
<LONGNAME>,which is Timeout N_As/N_Ar.These tags repeat and will have
different timer names..like

- <COMPARAM id="_339" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_BS </SHORTNAME>
<LONGNAME>Timeout N_Bs</LONGNAME>
<DESCRIPTION>Time that the transmitter of a multi-frame message
shall wait to receive a flow control (FC) frame before timing out with
a network layer error.</DESCRIPTION>
</COMPARAM>

I need to remove the words Timeout from the data,and
take only the abbrevation..i.e.N_As/N_bs like that .In short i have to
remove the words which come with name Time,and also the space which
comes next to it.
and take only the abbreviation.Can someone help me in this.
Thanks

May 14 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

On May 14, 2007, at 12:56 AM, sa**********@gmail.com wrote:
Hi,
I am parsing an xml file ,and one part of structure looks
something like this:

- <COMPARAM id="_338" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_AX </SHORTNAME>
<LONGNAME>Timeout N_As/N_Ar</LONGNAME>
<DESCRIPTION>Time from transmit request until a CAN frame transmit
confirmation is received.</DESCRIPTION>
</COMPARAM>

In my code i am extracting the data within
<LONGNAME>,which is Timeout N_As/N_Ar.These tags repeat and will have
different timer names..like

- <COMPARAM id="_339" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_BS </SHORTNAME>
<LONGNAME>Timeout N_Bs</LONGNAME>
<DESCRIPTION>Time that the transmitter of a multi-frame message
shall wait to receive a flow control (FC) frame before timing out with
a network layer error.</DESCRIPTION>
</COMPARAM>

I need to remove the words Timeout from the data,and
take only the abbrevation..i.e.N_As/N_bs like that .In short i have to
remove the words which come with name Time,and also the space which
comes next to it.
and take only the abbreviation.Can someone help me in this.
Thanks
Assuming you're naming the string 'logname' and the only space is
between the Time* word and the tags, this should work: logname.split()
[-1]
May 14 '07 #2

P: n/a
In <11*********************@o5g2000hsb.googlegroups.c om>, saif.shakeel
wrote:
Hi,
I am parsing an xml file ,and one part of structure looks
something like this:

- <COMPARAM id="_338" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_AX </SHORTNAME>
<LONGNAME>Timeout N_As/N_Ar</LONGNAME>
<DESCRIPTION>Time from transmit request until a CAN frame transmit
confirmation is received.</DESCRIPTION>
</COMPARAM>

In my code i am extracting the data within
<LONGNAME>,which is Timeout N_As/N_Ar.These tags repeat and will have
different timer names..like

- <COMPARAM id="_339" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_BS </SHORTNAME>
<LONGNAME>Timeout N_Bs</LONGNAME>
<DESCRIPTION>Time that the transmitter of a multi-frame message
shall wait to receive a flow control (FC) frame before timing out with
a network layer error.</DESCRIPTION>
</COMPARAM>

I need to remove the words Timeout from the data,and
take only the abbrevation..i.e.N_As/N_bs like that .In short i have to
remove the words which come with name Time,and also the space which
comes next to it.
and take only the abbreviation.Can someone help me in this.
You can test for the prefix with the `startswith()` method and use string
slicing to create a new string without the prefix:

In [3]: prefix = 'Timeout '

In [4]: longname = 'Timeout N_Bs'

In [5]: longname.startswith(prefix)
Out[5]: True

In [6]: longname = longname[len(prefix):]

In [7]: longname
Out[7]: 'N_Bs'

Ciao,
Marc 'BlackJack' Rintsch
May 14 '07 #3

P: n/a
On May 13, 10:56 pm, saif.shak...@gmail.com wrote:
Hi,
I am parsing an xml file ,and one part of structure looks
something like this:

- <COMPARAM id="_338" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_AX </SHORTNAME>
<LONGNAME>Timeout N_As/N_Ar</LONGNAME>
<DESCRIPTION>Time from transmit request until a CAN frame transmit
confirmation is received.</DESCRIPTION>
</COMPARAM>

In my code i am extracting the data within
<LONGNAME>,which is Timeout N_As/N_Ar.These tags repeat and will have
different timer names..like

- <COMPARAM id="_339" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_BS </SHORTNAME>
<LONGNAME>Timeout N_Bs</LONGNAME>
<DESCRIPTION>Time that the transmitter of a multi-frame message
shall wait to receive a flow control (FC) frame before timing out with
a network layer error.</DESCRIPTION>
</COMPARAM>

I need to remove the words Timeout from the data,and
take only the abbrevation..i.e.N_As/N_bs like that .In short i have to
remove the words which come with name Time,and also the space which
comes next to it.
and take only the abbreviation.Can someone help me in this.
Thanks
Did you get elementtree working?

May 14 '07 #4

P: n/a
On May 14, 1:04 pm, half.ital...@gmail.com wrote:
On May 13, 10:56 pm, saif.shak...@gmail.com wrote:


Hi,
I am parsing an xml file ,and one part of structure looks
something like this:
- <COMPARAM id="_338" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_AX </SHORTNAME>
<LONGNAME>Timeout N_As/N_Ar</LONGNAME>
<DESCRIPTION>Time from transmit request until a CAN frame transmit
confirmation is received.</DESCRIPTION>
</COMPARAM>
In my code i am extracting the data within
<LONGNAME>,which is Timeout N_As/N_Ar.These tags repeat and will have
different timer names..like
- <COMPARAM id="_339" DDORef="_18" Semantics="timing"
PhysicalLink="Infotainment_Control_Bus_CAN">
<SHORTNAME>Infotainment_Control_Bus_CAN_TIMEOUT_BS </SHORTNAME>
<LONGNAME>Timeout N_Bs</LONGNAME>
<DESCRIPTION>Time that the transmitter of a multi-frame message
shall wait to receive a flow control (FC) frame before timing out with
a network layer error.</DESCRIPTION>
</COMPARAM>
I need to remove the words Timeout from the data,and
take only the abbrevation..i.e.N_As/N_bs like that .In short i have to
remove the words which come with name Time,and also the space which
comes next to it.
and take only the abbreviation.Can someone help me in this.
Thanks

Did you get elementtree working?- Hide quoted text -

- Show quoted text -
Thanks for thr replies.It helped a lot.
Regarding the element tree problem,the module error is gone but a new
problem has appeared,which i have posted in new thread,

May 14 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.