String text ="65:234567
69:456789678
74:45678";
How do I get the text following 65: .I should be able to retrieve 234567.
I would not be able to get the text using str.substring(firstIdx + secondIdx) as the no of digits post ":" might change.
Please advice .
Related
Working with the automatic word Field codes a fun function is getting the File name.
The following correctly displays the file name in Upper case.
FILENAME \* Upper
Is there a way to also trim the length off the filename?
Example:
MyFileWithItsName.docx => I would like to only keep => MyFile
Thank you.
We receiving Input data like below
“VENKATA,KRISHNA”
I want output like below
VENKATA,KRISHNA
Can anyone help me with this
Check out the Ereplace function - it allows to replace certain characters so you could rplace " with '' (empty string).
An alternative is TRIM - you can specify which character the command should trim and also if All occurrences or Both (from both sides of the string) plus more.
following scenario: I want to display the length of a random word selected from a simple .txt list like this:
composer
circulation
fashionable
prejudice
progress
salesperson
disappoint
I used the following code to display one of these words from the list:
random_word_generator = open("random_words.txt", "r")
random_words = list(random_word_generator)
secret_word = random.choice(random_words)
however, whenever I want to print the length of the word by using:
print("My secret word is " + str(len(secret_word)))
It shows the length of the word - 1 character
like:
progress --> should be 8 letters, but python displays 7...
Do you know how this issue could be solved?
Btw: there are no spaces whatsoever in my .txt file
Kind Regards and many thanks in advance
You should mention the language you're using in the title and the tags.
To your question: Can you please paste the full code you're using? I tried your example, and it displays the correct length of each word (+ 1 for the newline character, which you could remove by calling .strip()), so I'm guessing you do something different.
random_word_generator = open("random_words.txt", "r")
random_words = list(random_word_generator) # ['composer\n', 'circulation\n', 'fashionable\n', 'prejudice\n', 'progress\n', 'salesperson\n', 'disappoint\n']
secret_word = random.choice(random_words) # "progress\n"
print("My secret word is " + str(len(secret_word))) # "My secret word is 9"
print("My secret word w/o newline is " + str(len(secret_word.strip()))) # "My secret word w/o newline is 8"
i am facing issue while converting unicode data into national characters.
When i convert the Unicode data into national using national-of function, some junk character like # is appended after the string.
E.g
Ws-unicode pic X(200)
Ws-national pic N(600)
--let the value in Ws-Unicode is これらの変更は. getting from java end.
move function national-of ( Ws-unicode ,1208 ) to Ws-national.
--after converting value is like これらの変更は #.
i do not want the extra # character added after conversion.
please help me to find out the possible solution, i have tried to replace N'#' with space using inspect clause.
it worked well but failed in some specific scenario like if we have # in input from user end. in that case genuine # also converted to space.
Below is a snippet of code I used to convert EBCDIC to UTF. Before I was capturing string lengths, I was also getting # symbols:
STRING
FUNCTION DISPLAY-OF (
FUNCTION NATIONAL-OF (
WS-EBCDIC-STRING(1:WS-XML-EBCDIC-LENGTH)
WS-EBCDIC-CCSID
)
WS-UTF8-CCSID
)
DELIMITED BY SIZE
INTO WS-UTF8-STRING
WITH POINTER WS-XML-UTF8-LENGTH
END-STRING
SUBTRACT 1 FROM WS-XML-UTF8-LENGTH
What this code does is string the UTF8 representation of the EBCIDIC string into another variable. The WITH POINTER clause will capture the new length of the string + 1 (+ 1 because the pointer is positioned to the next position after the string ended).
Using this method, you should be able to know exactly how long second string is and use that string with the exact length.
That should remove the unwanted #s.
EDIT:
One thing I forgot to mention, in my case, the # signs were actually EBCDIC low values when viewing the actual hex on the mainframe
Use inspect with reverse and stop after first occurence of #
I have a bunch of CSV files that have the data in a format of YYYY-MM-DD HH,value
I can split the hours off by running
with open(out_path+filename,'r+') as data_r:
comreader = csv.reader(data_r, delimiter=' ', quotechar='"')
for row in comreader:
print ','.join(row)
from this I get
'YYYY-MM-DD,HH',value
What I need to do is remove the (') from in front of YYYY and then after HH
You're using the quotechar parameter, but wrongly:
it should read "'" if you want to interpret ' as the character surrounding strings.
Other than that, you can get parts of strings easily with python's slicing abilities:
outstring = instring[1:-1]
will give you everything from the 1. (dropping the 0.) to (excluding it) the last character.