---
title: MAGIC function for returning the number of leading characters
description: A useful tip when creating a user-defined field that performs string extraction based upon the number of leading characters within a string.
---

[![IPeopleHealthcare_White](https://blog.ipeople.com/hubfs/IPeopleHealthcare_White.png)](https://www.ipeople.com/)

- [Home](https://www.ipeople.com)
- Products 
    - [Professional Services](https://www.ipeople.com/products/meditech-services/)
    - [Downtime Product Suite](https://www.ipeople.com/products/suite)
- [Benefits](https://www.ipeople.com/benefits)
- [About](https://www.ipeople.com/about)
- [Contact](https://www.ipeople.com/contact)
- [IPeople Blog](https://blog.ipeople.com)

November 4, 2021

# MAGIC function for returning the number of leading characters

l (that's a lowercase L) is the MAGIC function for returning the number of leading characters for a string.  It takes two arguments, the first of which is the string to search for leading characters, and the second of which is the character to check for. 

 l(0009876,0) returns 3 because the string 0009876 has three leading characters that match the second argument, 0.

This comes in handy on occasion, especially when creating a user-defined field that performs string extraction based upon the number of leading characters within a string.  Some facilities have their patient account numbers beginning with a long string of zeros and need those zeros excluded from the report.  Sometimes the number of leading zeros varies.

 Topics: [MEDITECH](https://blog.ipeople.com/topic/meditech), [Report Writing](https://blog.ipeople.com/topic/report-writing), [Tips & Tricks](https://blog.ipeople.com/topic/tips-tricks), [Magic Function](https://blog.ipeople.com/topic/magic-function), [Magic System](https://blog.ipeople.com/topic/magic-system), [NPR Report](https://blog.ipeople.com/topic/npr-report), [CS System](https://blog.ipeople.com/topic/cs-system)

## You Might Also Enjoy

<https://blog.ipeople.com/how-to-use-a-meditech-index-file-as-your-detail-segment-for-an-npr-report>

#### [How to use a MEDITECH Index File as your Detail Segment for an NPR Report](https://blog.ipeople.com/how-to-use-a-meditech-index-file-as-your-detail-segment-for-an-npr-report)

Suppose you want to produce a list of RXs for all current Inpatients. This example will ...

<https://blog.ipeople.com/how-to-access-npr-segments-that-are-not-available-as-detail-segments>

#### [How to Access NPR Segments that are not available as Detail Segments](https://blog.ipeople.com/how-to-access-npr-segments-that-are-not-available-as-detail-segments)

Sometimes MEDITECH does not make a segment available as a Detail Segment in their NPR ...

<https://blog.ipeople.com/detail-segment/index-file-information-screen-during-lookup>

#### [Detail Segment/Index File information screen during lookup](https://blog.ipeople.com/detail-segment/index-file-information-screen-during-lookup)

After pressing for a lookup for either Detail Segments or Index Files, press the number ...

<https://blog.ipeople.com/using-the-bfi-field-attribute-on-npr-report-writer-screens-magic-and-c/s>

#### [Using the BFI Field Attribute on NPR Report Writer Screens (MAGIC and C/S)](https://blog.ipeople.com/using-the-bfi-field-attribute-on-npr-report-writer-screens-magic-and-c/s)

BFI stands for Before Input. BFI attributes can come in pairs, just like FCL attributes. ...

<https://blog.ipeople.com/using-s-to-select-sort-fields-select-fields-and-report-fields>

#### [Using S\\ to select Sort Fields, Select Fields, and Report Fields](https://blog.ipeople.com/using-s-to-select-sort-fields-select-fields-and-report-fields)

When picking Select Fields, Sort Fields, or Report Fields, users can press for a lookup ...

[![IPeopleHealthcare_FullColor](https://blog.ipeople.com/hubfs/IPeopleHealthcare_FullColor.png)](https://www.ipeople.com/)

#### CONTACT

- [+1-214-222-1125](tel:+1-214-222-1125)
- [support@ipeople.com](mailto:support@ipeople.com)
- [sales@ipeople.com](mailto:sales@ipeople.com)

#### [JOIN OUR TEAM](https://ipeople.bamboohr.com/jobs/)

#### FOLLOW

- [![Facebook](https://blog.ipeople.com/hubfs/Facebook.svg)](https://www.facebook.com/IPeoplehealthcareTX)
- [![Instagram](https://blog.ipeople.com/hubfs/Instagram.svg)](https://www.instagram.com/interfacepeople/)
- [![Linkedin](https://blog.ipeople.com/hubfs/Linkedin.svg)](https://www.linkedin.com/company/ipeople-healthcare)
- [![Twitter](https://blog.ipeople.com/hubfs/Twitter.svg)](https://twitter.com/InterfacePeople)
- [![email_icon](https://blog.ipeople.com/hubfs/email_icon.svg)](mailto:support@ipeople.com)

 

![](https://blog.ipeople.com/hubfs/IPeople_2022_Aug/Images/Home/arrow-up.png)