Index: tests/test_func_fieldnum.c
===================================================================
--- tests/test_func_fieldnum.c	(revision 0)
+++ tests/test_func_fieldnum.c	(revision 0)
@@ -0,0 +1,122 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Gareth Palmer <gareth@acsdata.co.nz>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Function FIELDNUM tests
+ *
+ * \author\verbatim Gareth Palmer <gareth@acsdata.co.nz> \endverbatim
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+	<depend>TEST_FRAMEWORK</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision: 276114 $")
+
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+#include "asterisk/pbx.h"
+#include "asterisk/channel.h"
+
+static struct {
+	const char *value;
+	const char *delim;
+	const char *field;
+	const char *result;
+} test_args[] = {
+	{ "abc,def,ghi,jkl", "\\,", "ghi", "3" },
+	{ "abc#def#ghi#jkl", "#", "def", "2" },
+	{ "abc,def,ghi,jkl", "-", "",    "0" },
+	{ "abc-def-ghi-jkl", "-", "mno", "0" }
+};
+
+AST_TEST_DEFINE(test_func_fieldnum)
+{
+	int res = AST_TEST_PASS, i;
+	struct ast_channel *chan;
+	struct ast_str *str;
+	struct ast_var_t *var;
+	char expression[256];
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "func_fieldnum";
+		info->category = "/funcs/func_strings/";
+		info->summary = "Verify behavior of the FIELDNUM() dialplan function";
+		info->description =
+			"Verifies that the examples of the FIELDNUM() dialplan function documentation work as described.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(chan = ast_dummy_channel_alloc())) {
+		ast_test_status_update(test, "Unable to allocate dummy channel\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (!(str = ast_str_create(16))) {
+		ast_test_status_update(test, "Unable to allocate dynamic string buffer\n");
+		ast_channel_release(chan);
+		return AST_TEST_FAIL;
+	}
+
+	for (i = 0; i < ARRAY_LEN(test_args); i++) {
+		var = ast_var_assign("FIELDS", test_args[i].value);
+		AST_LIST_INSERT_HEAD(&chan->varshead, var, entries);
+
+		snprintf(expression, sizeof(expression), "${FIELDNUM(%s,%s,%s)}", var->name, test_args[i].delim, test_args[i].field);
+		ast_str_substitute_variables(&str, 0, chan, expression);
+
+		AST_LIST_REMOVE(&chan->varshead, var, entries);
+		ast_var_delete(var);
+
+		if (strcasecmp(ast_str_buffer(str), test_args[i].result)) {
+			ast_test_status_update(test, "Evaluation of '%s' returned '%s' instead of the expected value '%s'\n",
+				expression, ast_str_buffer(str), test_args[i].result);
+			res = AST_TEST_FAIL;
+			break;
+		}
+	}
+
+	ast_free(str);
+	ast_channel_release(chan);
+
+	return res;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(test_func_fieldnum);
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(test_func_fieldnum);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "FIELDNUM() Tests");
Index: CHANGES
===================================================================
--- CHANGES	(revision 279754)
+++ CHANGES	(working copy)
@@ -238,6 +238,7 @@
  * Added option to dialplan function CDR(), the 'f' option
    allows for high resolution times for billsec and duration fields.
  * FILE() now supports line-mode and writing.
+ * Added FIELDNUM, which returns the position number of a field in a list.
 
 Dialplan Variables
 ------------------
Index: funcs/func_strings.c
===================================================================
--- funcs/func_strings.c	(revision 279754)
+++ funcs/func_strings.c	(working copy)
@@ -61,6 +61,24 @@
 			<para>Example: If ${example} contains <literal>ex-amp-le</literal>, then ${FIELDQTY(example,-)} returns 3.</para>
 		</description>
 	</function>
+	<function name="FIELDNUM" language="en_US">
+		<synopsis>
+			Return the position number of a field in a list 
+		</synopsis>
+		<syntax>
+			<parameter name="varname" required="true" />
+			<parameter name="delim" required="true" />
+			<parameter name="value" required="true" />
+		</syntax>
+		<description>
+			<para>The delimiter may be specified as a special or extended ASCII character, by encoding it.  The characters
+			<literal>\n</literal>, <literal>\r</literal>, and <literal>\t</literal> are all recognized as the newline,
+			carriage return, and tab characters, respectively.  Also, octal and hexadecimal specifications are recognized
+			by the patterns <literal>\0nnn</literal> and <literal>\xHH</literal>, respectively.  For example, if you wanted
+			to encode a comma as the delimiter, you could use either <literal>\054</literal> or <literal>\x2C</literal>.</para>
+		<para>Example: If ${example} contains <literal>ex-amp-le</literal>, then ${FIELDNUM(example,-,amp)} returns 2.</para>
+		</description>
+	</function>
 	<function name="LISTFILTER" language="en_US">
 		<synopsis>Remove an item from a list, by name.</synopsis>
 		<syntax>
@@ -455,6 +473,58 @@
 	.read2 = function_fieldqty_str,
 };
 
+static int function_fieldnum(struct ast_channel *chan, const char *cmd,
+                             char *parse, char *buf, size_t len)
+{
+	char *varsubst, *field;
+	struct ast_str *str = ast_str_thread_get(&result_buf, 16);
+	int fieldindex = 0;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(varname);
+		AST_APP_ARG(delim);
+		AST_APP_ARG(field);
+	);
+	char delim[2] = "";
+	size_t delim_used;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+	if (args.argc < 3) {
+		ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n");
+		return -1;
+	}
+
+	ast_get_encoded_char(args.delim, delim, &delim_used);
+
+	varsubst = alloca(strlen(args.varname) + 4);
+	sprintf(varsubst, "${%s}", args.varname);
+
+	ast_str_substitute_variables(&str, 0, chan, varsubst);
+	if (ast_str_strlen(str) == 0) {
+		fieldindex = 0;
+	} else {
+		char *varval = ast_str_buffer(str);
+
+		while ((field = strsep(&varval, delim)) != NULL) {
+			fieldindex++;
+
+			if (!strcasecmp(field, args.field)) {
+				break;
+			}
+		}
+		if (!field) {
+			fieldindex = 0;
+		}
+	}
+	snprintf(buf, len, "%d", fieldindex);
+
+	return 0;
+}
+
+static struct ast_custom_function fieldnum_function = {
+        .name = "FIELDNUM",
+        .read = function_fieldnum,
+};
+
 static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len)
 {
 	AST_DECLARE_APP_ARGS(args,
@@ -1481,6 +1551,7 @@
 
 	AST_TEST_UNREGISTER(test_FILTER);
 	res |= ast_custom_function_unregister(&fieldqty_function);
+	res |= ast_custom_function_unregister(&fieldnum_function);
 	res |= ast_custom_function_unregister(&filter_function);
 	res |= ast_custom_function_unregister(&replace_function);
 	res |= ast_custom_function_unregister(&listfilter_function);
@@ -1513,6 +1584,7 @@
 
 	AST_TEST_REGISTER(test_FILTER);
 	res |= ast_custom_function_register(&fieldqty_function);
+	res |= ast_custom_function_register(&fieldnum_function);
 	res |= ast_custom_function_register(&filter_function);
 	res |= ast_custom_function_register(&replace_function);
 	res |= ast_custom_function_register(&listfilter_function);
