string-manipulation

PHP conditional string replacement

I'm trying to replace the ~ into | between the [ ] in the folowwing case: {stackoverflow is a [cool~great~fast] website ~ Find your answers [easily~quickly] on stackoverflow}. Note: The text between the [ ] can be multiline. I've tried multiple regexs buth with no luck. My closest call at the moment is: $text = preg_replace("/\[(.*...

Python: finding files with matching extensions or extensions with matching names in a list.

Suppose I have a list of filenames: [exia.gundam, dynames.gundam, kyrios.gundam, virtue.gundam], or [exia.frame, exia.head, exia.swords, exia.legs, exia.arms, exia.pilot, exia.gn_drive, lockon_stratos.data, tieria_erde.data, ribbons_almark.data, otherstuff.dada]. In one iteration, I'd like to have all the *.gundam or *.data files, where...

Find the rightmost occurrence of a string t, in a string s.

Corrected code: int strrindex(char *s, char *t) { int i, j, k, p; i = -1; for (k = 0; s[k] != '\0'; k++) { if (strlen(s) < strlen(t)) break; if (s[k] == t[0]) { for (p = k; s[p] != '\0'; p++) { j = p; while (s[j] != '\0' && s[j] == t[j-k] && t[j-k] != '\0') { j++; } if (t[j-k] != '\0') { break; ...

How to remove '<' from a string?

say, i have a string like $x="History[424]<"; how to remove the last "<" and make the string $x="History[424]"; ... I tried str_replace and don't know, its not working... :(. Thx in advance for($k=0;$k<$i;$k++) { $linklabelmod[$k] = str_replace($linklabel[$k], $linklabel[$k]."[$k]", $linklabel[$k]); //$var= str_replace($lin...

string manipulation

what to do if i want to replace only the first occurance of a word in a string. eg: I want to change the first occurance of heelo in a string with kiran. input string == **"hello world i am a noob hello to all"** output string == **"kiran world i am a noob hello to all"** the str_replace is not working.... Thx in advance.... ...

php curl, link label modifying through proxy website, not fully working

Here is the code <?php $url='http://isrc.ulster.ac.uk'; $var = fread_url($url);// function calling to get the page from curl $i=0; $linklabel = array(); $linklabelmod = array(); $link = array(); $dom = new DOMDocument(); @$dom->loadHTML($var); $xpath = new DOMXPath($dom); foreach($xpath->query('//a') as $element) { $linklabel[] = ...

Given this string (with '\n') how can I strip it from all the returns?

Here's the string: \n\n\t\thttp://www.linkedin.com/in/ckenworthy\n\n\t How can I strip everything so I only end up with: http://www.linkedin.com/in/ckenworthy I've tried the following: string value = doc.XPathSelectElement("/ipb/profile/contactinformation/contact[title/text() = 'LinkedIn']/value").Value; value = va...

Formatting String into MYSQL time

Ok, So i have a script that reads in a csv file and in there is a time that is formatted in the traditional HH:MM am/pm. I need to convert that into the mysql standard time format (HH:MM:SS). This is what i have so far and it works $schedule[$row]["TIME"] = date("H:i:s", strtotime($data[4])) the problem is, if the input is formatted...

string manipulation pre_replace or str_replace

I need to replace a word with another word. But $var= str_replace($linklabel[$k], $linklabelmod[$k], $var); is not giving the desired result. For example i have a string $var="the theory of them thesis"; $linklabel[1]="the"; $linklabelmod[1]="hhh"; What i need is, i just want to replace the word "the". But since "the" is repeat...

In PHP, Removing first element in CSV String

I'm simply looking to take the first csv out of a string, using PHP. Here are a few examples: "Sea Bass, Floured Or Breaded, Fried" => "Floured Or Breaded, Fried" "Tuna, Fresh, Baked Or Broiled" => "Fresh, Baked Or Broiled" "Croaker, Breaded Or Battered, Baked" => "Breaded Or Battered, Baked" And so on... Thank you. ...

How to remove all break tags from a string in PHP?

Seems simple enough but I'm having some issues, I tried using preg_replace: preg_replace("<br />", "", $string); But what I get is this <> in place of the <br /> in the string when outputted. The break tags in the string will always be in this format not in any of these: <br/> <br> <BR /> etc. so what's the error I'm making? ...

Java string-manipulation problem !

I must write a function that takes two words (strings) as arguments, and determines if the first word can be transformed into the second word using only one first-order transformation. First-order transformations alter only one letter in a word The allowed transformations are: insert, remove and replace insert = insert a letter at an...

Index of substring in SQLite3?

What's the most straightforward way of finidng the index of a substring in a varchar column? charindex doesn't exist in the stock version of SQLite3 -- which is still a little surprising to me. Specifically, I have a column with values like 010000, 011000, 010110, etc. I want to find the index of the first occurence of 11. For the ex...

remove dot at end of text

i have to remove the dot at the end of text howt to i do usign c#, dot.net example = abc. i want this = abc ...

PHP - if condition inside string

An easy question to ask, hope not to stupid. $var=0; $condition="$var!=0"; if($condition) { # do something # } else { # do something else # } Obviously the code up there doesn't work as intended. Is there a nice way to obtain an if-condition from a string? Or do I have to parse the string in some disturbing way? EDIT I didn't...

String manipulation & memory allocation - C

I am in the process of learning C. I have a method that takes 3 strings and combines them to do some operation. Following was my first implementation using a GCC compiler. void foo(const char *p1, const char *p2, const char *p3) { size_t length = strlen(p1) + strlen(p2) + strlen(p3); char combined[length + 1]; memset(combin...

string.find using directory path in Lua

Hello, I need to translate this piece of code from Perl to Lua open(FILE, '/proc/meminfo'); while(<FILE>) { if (m/MemTotal/) { $mem = $_; $mem =~ s/.*:(.*)/$1/; } elseif (m/MemFree/) { $memfree = $_; $memfree =~ s/.*:(.*)/$1/; } } close(FILE); So far I've written ...

Removing up to 4 spaces from a string

Hello I have an array of Strings Im looping through. For each string, I need to remove up to 4 spaces from the beginning. In other words, if there are only 2 spaces, I remove 2. If there are 6 spaces I remove 4. How can I specify this in the loop? for(int i=0; i<stringArray.length; i++) { newString = REMOVE UP TO 4 SPACES FROM stri...

memmove leaving garbage - C

I wrote the following function to split the given full path into directory, filename and extension. #include <stdio.h> #include <string.h> #include <stdlib.h> struct path_info { char *directory; char *filename; char *extension; }; #ifdef WIN32 const char directory_separator[] = "\\"; #else const char directory_separator[]...

PL/SQL String Manipulation

I need to split an address which is a single string into multiple strings. Below are the requirements to for the pl/sql procedure that splits up the address into the corresponding address lines. The parameters of the procedure are: create or replace procedure split_address ( address in varchar2, al1 out varchar2, al2 out varchar2, al3 o...