I have a column of strings separated by comma.
Example: City, Zipcode
I want to make a column with only city populated so everything before the comma.
How has anyone else accomplished this? I know with Foxpro you can usually accomplish the same task various ways. Any help would be appreciated.
EDIT: SOLUTION
GETWORDNUM(FIELD,1,",")
This worked to give the text string before the comma from the column FIELD.
The easiest way to do that is to use STREXTRACT(). ie:
lcColumnData = "City, Zipcode"
? STREXTRACT(m.lcColumnData, "",",")
STORE ALINES(aCZ, "Atlanta, 30301", ",") TO iCZ
City = aCZ[1]
ZipCode = aCZ[2]
?City
?ZipCode
Try this:
str = "City, Zipcode"
*initialize the column value leftcol
leftcol = ''
*find comma position
pos = At(',', str)
Do Case
Case pos > 1
* there is a comma and something before that. take everything before that pos
leftcol = Left(str, pos-1)
Case pos = 1
* first char is comma
leftcol = ''
Otherwise
*there is no comma. take the whole string
leftcol = str
EndCase
Related
Here's the deluge script to capitalize the first letter of the sentence and make the other letters small that isn't working:
a = zoho.crm.getRecordById("Contacts",input.ID);
d = a.get("First_Name");
firstChar = d.subString(0,1);
otherChars = d.removeFirstOccurence(firstChar);
Name = firstChar.toUppercase() + otherChars.toLowerCase();
mp = map();
mp.put("First_Name",d);
b = zoho.crm.updateRecord("Contacts", Name,{"First_Name":"Name"});
info Name;
info b;
I tried capitalizing the first letter of the alphabet and make the other letters small. But it isn't working as expected.
Try using concat
Name = firstChar.toUppercase().concat( otherChars.toLowerCase() );
Try removing the double-quotes from the Name value in the the following statement. The reason is that Name is a variable holding the case-adjusted name, but "Name" is the string "Name".
From:
b = zoho.crm.updateRecord("Contacts", Name,{"First_Name":"Name"});
To
b = zoho.crm.updateRecord("Contacts", Name,{"First_Name":Name});
I want to remove extra spaces from the text, i referenced the code from the internet as below:
(text as text)=>
let
x = Text.Split(text," "),
y = Text.Select(x,each _<>""),
z = Text.Combine(y," ")
in
z
when i apply this function for my data , it show the error is "Expression.Error: We cannot convert a value of type List to type Text." , my column is definitely is text format already , i don't know root of the issue, could you please help look ?
my data is very simple, like below:
You can use below code as a custom function:
(text as text, optional char_to_trim as text) =>
let
char = if char_to_trim = null then " " else char_to_trim,
split = Text.Split(text, char),
removeblanks = List.Select(split, each _ <> ""),
result=Text.Combine(removeblanks, char)
in
result
I want extract from a table all rows where in a column (string) there is at least one word that starts with a specified character.
Example:
Row 1: 'this is the first row'
Row 2: 'this is th second row'
Row 3: 'this is the third row'
If the specified character is T -> I would extract all 3 rows
If the specified character is S -> I would extract only the second column
...
Please help me
Assuming you mean "space delimited sequence of characters, or begin to space or space to end" by "word", then you can split on the delimiter and test them for matches:
var src = new[] {
"this is the first row",
"this is th second row",
"this is the third row"
};
var findChar = 'S';
var lowerFindChar = findChar.ToLower();
var matches = src.Where(s => s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Any(w => w.ToLower()[0] == lowerFindChar));
The LINQ Enumerable.Any method tests a sequence to see if any element matches, so you can split each string into a sequence of words and see if any word begins with the desired letter, compensating for case.
Try this:
rows.Where(r => Regex.IsMatch(r, " [Tt]"))
You can replace the Tt with Ss (both assuming you want either upper case or lower case).
The problem of course is, what is a "word"?
Is the character sequence 'word' in the sentence above a word according to your definition? It doesn't start with a space, not even a white-space.
A definition of a word could be:
Define wordCharacter: something like A-Z, a-z.
Define word:
- the non-empty sequence of wordCharacters at the beginning of a string followed by a non-wordcharacter
- or the non-empty sequence of wordCharacters at the end of a string preceded by a non-wordcharacter
- any non-empty sequence of wordCharacters in the string preceded and followed by a non-wordcharacter
Define start of word: the first character of a word.
String: "Some strange characters: 'A', 9, äll, B9 C$ X?
- Words: Some, strange characters, A
- Not Words: 9, äll, B9, C$ X?
So you first have to specify precisely what you mean by word, then you can define functions.
I'll write it as an extension method of IEnumerable<string>. Usage will look similar to LINQ. See Extension Methods Demystified
bool IsWordCharacter(char c) {... TODO: implement your definition of word character}
static IEnumerable<string> SplitIntoWords(this string text)
{
// TODO: exception if text null
if (text.Length == 0) return
int startIndex = 0;
while (startIndex != text.Length)
{ // not at end of string. Find the beginning of the next word:
while (startIndex < text.Length && !IsWordCharacter(text[startIndex]))
{
++startIndex;
}
// now startIndex points to the first character of the next word
// or to the end of the text
if (startIndex != text.Length)
{ // found the beginning of a word.
// the first character after the word is either the first non-word character,
// or the end of the string
int indexAfterWord = startWordIndex + 1;
while (indexAfterWord < text.Length && IsWordCharacter(text[indexAfterWord]))
{
++indexAfterWord;
}
// all characters from startIndex to indexAfterWord-1 are word characters
// so all characters between startIndexWord and indexAfterWord-1 are a word
int wordLength = indexAfterWord - startIndexWord;
yield return text.SubString(startIndexWord, wordLength);
}
}
}
Now that you've got a procedure to split any string into your definition of words, your query will be simple:
IEnumerabl<string> texts = ...
char specifiedChar = 'T';
// keep only those texts that have at least one word that starts with specifiedChar:
var textsWithWordThatStartsWithSpecifiedChar = texts
// split the text into words
// keep only the words that start with specifiedChar
// if there is such a word: keep the text
.Where(text => text.SplitIntoWords()
.Where(word => word.Length > 0 && word[0] == specifiedChar)
.Any());
var yourChar = "s";
var texts = new List<string> {
"this is the first row",
"this is th second row",
"this is the third row"
};
var result = texts.Where(p => p.StartsWith(yourChar) || p.Contains(" " + yourChar));
EDITED:
Alternative way (I'm not sure it works in linq query)
var result = texts.Where(p => (" " + p).Contains(" " + yourChar));
you can use .ToLower() if you want Case-insensitive check.
Let's say I had someone enter the text 'Name: Bob'
Is there any way I can extract the right side of the colon if I know what's on the left?
For example, if I knew that the left side of the colon was 'Name,' could I extract 'Bob' and how would I do that?
Just by knowing that the string contains a colon, you can separate the string into two parts with the parts containing the string on each side of the colon.
let str = "Name: Bob"
let comp = str.components(separatedBy: ":") //returns an array of strings
let name = comp[1] //returns "Bob"
If you also want to remove the whitespace before the name, you can either do let comp = str.components(separatedBy: ": ") or if you want to be more generic, let name = comp[1].replacingOccurrences(of: " ", with: "")
I've this string:
TEST|TEST1|TEST3|TEST4|TEST5|TEST6|TEST7|TEST8|
I need to select TEST8 using VBS. Is there a better way then using MID/INSTR? For example, selecting directly only the characters UNTIL | from right to left?
PS.: I only have these functions available:
Ascii
Char
Compare
DigText
Format
InStr
LCase
Len
Left
LTrim
Mid
Right
RTrim
Trim
UCase
Use Split(), if your data is a string with parts separated by a simple separator; use UBound() to get at the last element in a flexible way:
>> s = "TEST|TEST1|TEST3|TEST4|TEST5|TEST6|TEST7|TEST8"
>> a = Split(s, "|")
>> WScript.Echo a(Ubound(a))
>>
TEST8