- Posts: 4
Split addressrow into name; number; letter
- Per-Olof Hermansson
- Topic Author
- Offline
- User
Less
More
6 years 3 months ago - 6 years 3 months ago #3453
by Per-Olof Hermansson
Split addressrow into name; number; letter was created by Per-Olof Hermansson
I often receive addresses where the postaladdress is contained in one field, but in our system we register the different parts of the addressrow in separate fields,
and I need to split them accordingly.
For Example: 'Lindhult Höjden 5A' needs to be 'Lindhult Höjden'; '5'; 'A'
Is this possible with Flowheater?
Thanks
Per-Olof
and I need to split them accordingly.
For Example: 'Lindhult Höjden 5A' needs to be 'Lindhult Höjden'; '5'; 'A'
Is this possible with Flowheater?
Thanks
Per-Olof
Last edit: 6 years 3 months ago by Per-Olof Hermansson.
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
6 years 3 months ago #3457
by FlowHeater-Team
Best wishes
Robert Stark
Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.
Replied by FlowHeater-Team on topic Split addressrow into name; number; letter
Hi Per-Olof,
It would be posible but you need the help of the .NET Script Heater and the little C# script below.
The script first finds out whether a number is a part of the adresse field and store the index of the first and the last occurience. Then the script build a new string with the delimiter “#” for each part. This string you can split with the String Split Heater an store the result in separate fields.
Please find attached a little example.
C# script to split address row
It would be posible but you need the help of the .NET Script Heater and the little C# script below.
The script first finds out whether a number is a part of the adresse field and store the index of the first and the last occurience. Then the script build a new string with the delimiter “#” for each part. This string you can split with the String Split Heater an store the result in separate fields.
Please find attached a little example.
C# script to split address row
Code:
public object DoWork()
{
if (InValues.Length < 1)
throw new Exception("1 input parameter expected!");
// get the first input parameter
string s = (string)InValues[0].GetString();
string output = String.Empty;
int posFirstNumber = -1;
int posLastNumber = -1;
int lastPos = s.Length - 1;
// check whether a number is a part of the address and get the first and last index
for (int i = s.Length - 1; i >= 0; i--)
{
// check whether the character is nummeric?
if (IsNumeric(s[i]))
{
if (posLastNumber == -1)
posLastNumber = i;
}
else if (posLastNumber != -1 && posFirstNumber == -1)
posFirstNumber = lastPos;
lastPos = i;
}
if (posFirstNumber != -1)
{
// create output for the Split Heater
output = s.Substring(0, posFirstNumber - 1);
output += "#";
output += s.Substring(posFirstNumber, posLastNumber - posFirstNumber + 1);
output += "#";
if (posLastNumber < s.Length)
output += s.Substring(posLastNumber + 1);
}
else
{
// no number in address found
output = s + "##";
}
return output;
}
public bool IsNumeric(char c)
{
int output;
return Int32.TryParse(c.ToString(), out output);
}
Best wishes
Robert Stark
Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.
Attachments:
Please Log in or Create an account to join the conversation.
Time to create page: 0.261 seconds