Solved

Convert String to Char?

Posted on 2001-08-28
3
350 Views
Last Modified: 2010-04-06
This is probably very easy, but still:

I would like to return the ord() value of a character:

ord('c') returns 99

but if I try to extract the letter from a string like this:
 Mystring := midstr(strLongString,nbrStartPos,1); //e.g 'c'

and then want to use the function

 nbrThatItIs := ord(Mystring);

I get an error because Mystring is "string" and I need to use Char.

So: How do I best convert my string to char?

0
Comment
Question by:bjornborg
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
edey earned 30 total points
ID: 6433187
to get the ord value of the _third_ char in a string, try this:

ord(myString[2]);


GL
Mike
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6433746
Edey, i think you mean "the value of the _second_ char
in a string" and the _third_ in a PChar. :-)

s = '123';
 
ord(s[2]);         -> "2"
ord(PChar(s)[2]);  -> "3"
0
 
LVL 6

Expert Comment

by:edey
ID: 6434106
Umm, yeah, that's right! Sorry about the little mixup :).

GL
Mike
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question