Odoo Help

0

How to get a first character from a string?

By
vadivel
on 1/31/15, 1:16 AM 1,993 views

Hi Friends,

I have to split a character from string.

For Example,If Name is like Sai Sathi Bawan,I have to split a first character from these strings as SSB and have to join these characters.How can we achieve this?Please help me in this friends.Thanks in advance

 

 

2
Stephen Mack
On 1/31/15, 1:21 AM

In python you can limit your string by using the VARIABLE[:NUMBER] format.

First character of a string

my_string[:1]

First five characters of a string

my_string[:5]

Last seven characters of a string

my_string[:-7]

So what you need is highlighted in bold

my_name = "Sai sathi bawan"
my_initals = ''.join([s[:1] for s in my_name.split(' ')])
print(my_initals)

Output: Ssb

To force Upper Case...

my_name = "Sai sathi bawan"
my_initals = ''.join([s[:1].upper() for s in my_name.split(' ')])
print(my_initals)

Output: SSB

updated response

Stephen Mack
on 1/31/15, 2:00 AM

Thank you so much Stephen Mack for your response.Its mean a lot to me

vadivel
on 1/31/15, 2:27 AM

Sure no problem. Have a good day.

Stephen Mack
on 1/31/15, 2:30 AM

Usefull Example Stephen Mack...

Odoo
on 2/2/15, 8:48 AM

One more help.Mack i want to swap characters 6361 result as 6163 How it is possible??

vadivel
on 2/3/15, 5:08 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/31/15, 1:16 AM
Seen: 1993 times
Last updated: 3/16/15, 8:10 AM